4 ms·
to be able to detect the difference between "this expression is a function" and "this expression is the result of the computation of a function" the parenthese
by _ZeD_ 5y ago
to be able to detect the difference between "this expression is a function" and "this expression is the result of the computation of a function"
the parentheses are not for function arguments, are for "invocation".
- yawaramin 5y agoCan you show an example of how they could be confused?
- dragonwriter 5y ago> to be able to detect the difference between "this expression is a function" and "this expression is the result of the computation of a function" If function (or method) arguments don't require parenthesis, referring to (rather than calling) a function/method usually requires quite distinct syntax, so it's quite easy to it apart from a call. It may not be familiar to people coming from languages where no-parens refers to the function and parens call it, but being clear and distinct and being intuitive to people indoctrinated in contrary syntax are not the same thing. E.g., in ruby (which has methods but not functions in the strict sense) I can call a method with: thing.square # or thing.square() Or access the corresponding method object with: thing.method :square # or, thing.method(:square) Either of the former options are distinct from both of the latter.
- aylmao 5y agoA syntactic feature like this can only be judged in the context of the language. I'm sure there's languages where parentheses around function arguments prevent ambiguity, but there's also languages where it's very unambiguous, or the opposite might be true. For other examples of languages where invocations don't use parentheses for arguments, OCaml and Haskell. In fact, I'd argue that if they tried to add that feature to those languages (parens around arguments to a function), it'd make things very confusing given the way functions and tuples work.