-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Operators cannot be used with single-argument function shorthand in some cases #854
Comments
The others are as designed (so far) : the function arrow goes where the See also #480 for some ideas for improvements. |
Thanks for the link. This is exactly what I couldn't find yesterday. The subject is complex, but the feature itself, in my opinion, is very useful. I agree that examples with binary operations are ambiguous. It seems to me that the problem is that Civet interprets this ambiguity without considering it an error. From the user's point of view, + is a commutative operation, but Civet violates this and produces working code in one case and invalid code in another: arr.map(a + ($ => $.b))
collection.filter(!($ => $.condition)) This is now syntactically correct code. Some thoughts.
This shorthand was not a function at all in Ruby. This was just a short way to write the code of a block in which only one method is called. Combining & with operators is not allowed. The use of & is allowed only in one strict context and could not be included in a complex expression with other operators. For some reason this is allowed in Civet. For the user this raises the question: what is It is because of the last question that I remember the short form of notation of functions in the Wolfram Language. The ampersand is used at the end of the expression, and collection.filter(not #.condition &)
arr.filter(a and #.b &)
arr.map(1/# &)
arr.reduce(#1 + #2 &) This way it would be possible to use expressions in which the argument could goes anywhere, and it would also be possible to use more than one argument (which is so missing for use in the reduce function). Markers I'll think about it some more and I'd even like to try to change something in the Civet code, but I don't have as much free time for this as I'd like. |
I wrote some nonsense here. This construct is simply a kind of method reference in Ruby. Of course, we are not talking about Ruby, but about the desire to use a short syntax for very simple functions. |
Perhaps we should continue discussion in the #693 thread, which was about this issue. Meanwhile, #883 fixes I'm familiar with Mathematica/Wolfram notation. Personally I've found it extremely counterintuitive, especially to read but also to write (despite knowing shell scripts where
See also #85 for thoughts on re-using I think there could be nice ways to handle the binary case, with the same limitations as |
It seems to me that I saw a discussion of a similar problem somewhere here a few months ago, but I couldn’t find it now and could have confused it with something, so I’ll write just in case, since I encountered this in practice.
At first I thought this only applied to the humanized NOT operator:
But it turned out that for binary operators this approach does not work at all (presumably):
It seems to me that this should either work or not work in all cases at once.
The text was updated successfully, but these errors were encountered: