3 ms·
Well, the "f x" notation for function calls comes from the tradition of functional programming languages, where functions calls form the bulk of the code. It ma
by omaranto 6y ago
Well, the "f x" notation for function calls comes from the tradition of functional programming languages, where functions calls form the bulk of the code. It makes sense to make the most common operation have the lightest syntax.
Also, I suspect there is a misunderstanding in the "f a b" case. In the languages that use this syntax functions only have one argument, so that parses as "(f a) b". Both spaces means the same thing: evaluate a function; first evaluate f with argument a, which returns a function f a, then evaluate this function f a with the argument b.
In these languages, what would be a two argument function in other languages, you would define instead in either of these two fashions:
- As a function of a single argument which is a pair. So "f (a,b)" (which can be written as "f(a,b)" for short) calls f with a single argument, namely the pair (a,b).
- As a function returning a function that uses the second argument, the "f a b" style, which means "(f a) b".
These two forms are equivalent, different functional languages tend to prefer one or the other (SML, Ocaml and F# tend to use "f(a,b)", while Haskell tends to use "f a b"). Passing between one form and the other is called currying in one direction (I always forgot which one!) and uncurrying in the opposite direction.
- ledauphin 6y agoyep, this is what i was missing. I'd forgotten that it was common to be strict about functions always doing partial application, such that `f a` calls a function creating a partially-applied function. thank you for taking the time to clear this up for me!