0

This question may be too specific; however, I believe the variety of answers from the knowledgeable might be immensely helpful with respect to understanding dynamic languages such as Javascript (the language basis for my question).

Just to catch everyone reading up to a common place, here is some literature:

Liskov's (2001) Program Development in Java describes a total procedure as total if ..."its behavior is specified for all legal inputs," (54). A partial, then (as she also writes), is partial if illegal input is allowed and the behavior for that input undefined.

Though a few subtleties are not explained above, the distinction from my own research between total and partial appears pretty distinct, particularly for statically typed languages. From my understanding, the term "partial" is most often used to refer to the allowance of breaking formal parameters to procedures - arguments that cause an unhandled error within the body of the procedure.

Are procedures written in a dynamically typed language - here for primitive inputs - partial or total?

If you've got the book, another page to look at carefully is p. 58 (if not, you can find a pretty solid pdf of it online, somewhere).

Note (concerning comments):

I understand the notions of partial and total are language independent and refer specifically to each procedure;'s implementation; however, I am asking this about dynamically-typed languages in general where "legality" of input - and the enforcement of those rules - appears to be less well defined

Thomas
  • 6,291
  • 6
  • 40
  • 69
  • 1
    You might be interested in [Does JavaScript have undefined behaviour?](http://stackoverflow.com/q/14863430/1048572) – Bergi Jan 31 '15 at 14:25
  • Cool! That's an awesome addition, yes. – Thomas Jan 31 '15 at 14:39
  • 1
    After having read that chapter, I'd say that totality is a property of the single procedure, and does not have anything to do with the language it is written in. It's true that [some languages](https://en.wikipedia.org/wiki/Total_functional_programming) make it easier to write total procedures, or are better at warning you about partial procedures (by giving you more elaborate control on the "legality" of values), but it's the programmer who writes partial functions not the language. – Bergi Jan 31 '15 at 14:46
  • Interesting. I had not seen that linked terminology, before. I'll have to check it out. The criterialon "terminating" is a good one to add when thinking about totality. – Thomas Jan 31 '15 at 14:49

1 Answers1

1

There's some uncertainty in what is meant by "legal inputs" in the context of JavaScript. A function can be invoked with any number of arguments, regardless of how it is defined.

That said, I don't think JavaScript functions are inherently either. This can't be answered in the general case. Certainly partial functions are easy to produce, but I think total functions (by your definition) are also possible:

function total_function(i) {
  return 1;
}

Here, all possible inputs yield an output of 1. It doesn't matter whether you invoke the function as total_function() or total_function(1, 2, 3, 4, 5, 6, 7) or total_function('this is a string').

user229044
  • 232,980
  • 40
  • 330
  • 338
  • Thank you. Yes, that's really my conclusion too, I think. The idea of 'legal' is a bit different when thinking about JavaScript. – Thomas Jan 31 '15 at 14:38