Function Call Operator ’()‘ cannot be used continuously #2743
Replies: 10 comments
-
Indeed, this is unfortunately not possible: it conflicts with implicit multiplication. |
Beta Was this translation helpful? Give feedback.
-
You're right. It's a pity that I can't do magic like that. I can only do it like this 🤣 > f(x)=g(y)=x+y
// f(x)
> f(1)
// g(y)
> a=f(1)
//g(y)
> a(2)
// 3 |
Beta Was this translation helpful? Give feedback.
-
Indeed. If you have these curried functions it may be easier to create a helper function around |
Beta Was this translation helpful? Give feedback.
-
Alternatively, we might add a virtual property
It's a bit ugly, but it solves the problem. |
Beta Was this translation helpful? Give feedback.
-
That is an interesting idea, that would definitely work. I'm not sure if the need for it is high enough right now to justify implementing it. Current solution is to create an intermediate variable which is verbose but works too. |
Beta Was this translation helpful? Give feedback.
-
Some observations:
Let me know if either (1) or (2) is agreeable and I will be happy to work up a PR for either or both. |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
(1) well but they are already handled differently: 3(4,5) is s syntax error but 3(4) is 12. In other words, currently EXPR(A) has a wider range of semantics than EXPR(A,B), so why not extend EXPR(A,B) as well, consistent with doing what the client expects as often as possible? If EXPR evaluates to a function of two arguments, I don't think anyone will be surprised by EXPR(A,B) calling that function. (2) a) I assume you meant (2) b) There is precedent for assigning EXPR1 REST a different meaning than (EXPR1) REST even specifically in relation to implicit multiplication: 3 / 4x is (3/4)x but (3)/4 x is 3/(4x). So why not use a similar distinction to ease computed function calls? Providing an explicit syntax for computed function calls seems no "trick" to me. (3) My mistake: I had tried similar things like |
Beta Was this translation helpful? Give feedback.
-
(1) 😂 good point. Yes, I'm OK with changing the behavior of |
Beta Was this translation helpful? Give feedback.
-
Ok, I will work up a PR for EXPR(A,B) being a function call. And that suggests another alternative for forcing a function call: f(1)(2,) could call the result of f(1) on 2. It would probably not be hard as a consequence of EXPR(A,B) favoring function calls. It's like optional final comma in arrays and objects, just here it's in argument lists. |
Beta Was this translation helpful? Give feedback.
-
Function Call Operator ’()‘ cannot be used continuously
just like this
Beta Was this translation helpful? Give feedback.
All reactions