-
Notifications
You must be signed in to change notification settings - Fork 25
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
Consider syntactic marker to indicate a partial application #13
Comments
One option is to have a prefix // on its own:
const addOne = ^add(?, 1);
// pipeline:
const countOfBooksByAuthor = library
|> ^descendantsAndSelf(?)
|> ^filter(?, node => node.category === "programming")
|> ^groupBy(?, node => node.author);
// expressions:
const g = ^f(?, { option: ? }); Prefix const x = a
^ f() This would always be interpreted as |
@waldemarhorwat also pointed out that if we allow If we choose eager evaluation, then:
If we choose deferred evaluation, then:
|
Another question to consider: Should
|
That was one of Waldemars reasons for wanting a syntactic marker in the first place. |
changing foo(x++, y(g, h, i, j), m * n, "hello", bar, ...) becomes foo(x++, y(g, h, i, j), m * n, "hello", bar, ...?) and so bonus: adding the |
The decision of whether to go this direction seems to hinge on whether While a valid use of partial application and similar semantics to arrow functions, it also seems likely to cause confusion. It would be useful to know whether enforcing ignoring of arguments by the partially-applied function is a core use case. If not, @obedm503 's proposal of One other consideration is that there are only so many available syntatic markers that can be used in this position, so we should carefully consider whether this is worth using one for, forever. |
The initial reason that a syntactic marker was requested was the "garden path" problem, that you wind your way along the "garden path" of a function call and only at the end see a trailing I don't see much value in the syntactic marker. While the "garden path" concern is valid for very complex cases, the more frequent cases will be using partial application with pipeline ( |
|
Now that you mention it It is confusing |
If we use this expression
|
How about a shorthand form of the arrow functions that can be used for partial application? This would make the intent -- a function that passes arguments to another function -- closer to the form. Also, since this is very similar to the functionality of the piping operator Have |
problem is, |
@obedm503 sorry, my post has been edited since the version you saw.
Well, that's because it is defining a function
That's why the TC39 panel had an issue with it: it looks like a call instead of the definition it actually is |
That's just the function value itself, no? Is there a reason to need some special partial-application behavior for this case? |
@tabatkins It's confusing, but no. The partially-applied function with no arguments would ignore any further values passed to it. Take as an example One can of course question whether the token approach is worth having solely for this reason, unless there were other strong reasons to go the token route. Hard to imagine a lot of use for this case. |
Ah, makes sense. It affirmatively locks down the calling signature. I agree that this, by itself, isn't a strong motivating case for an identifying glyph, but I wouldn't say no to it if the other reasons for a glyph won out. |
What about using the backslash
Why does especially the backslash make sense here? Well similar to escaping characters in string literals, The major advantage over the circumflex |
Could we use a different sigil than the circumflex? Maybe I'll note that the circumflex might provide a syntax ambiguity with bitwise exclusive or when used as an expression statement with parentheses. (It also just looks odd.) |
I've been doing React for a while and having a syntactic marker to indicate a partial application would often make a lot of sense in that domain. Current way of doing things:
Hopefully the futureway of doing things ~
|
@jEnbuska Infix is not a great idea IMHO. It still looks too much like a function call. |
@fmease It's not illegal. See this article. In your case, it is illegal, but you still need lookahead to determine whether its a partial application or not. |
If you do accept using a syntactic marker, this proposal will be essentially a subset of the partial expression proposal. |
Not just arrow functions exhibit garden path, as @rbuckton mentioned, but method shorthands as well:
They pretty much seem like an invocation until you get to the braces or recognize the object context. While I admit that it might be less of a source of confusion, still I think it further lessens the weight of the "garden path" concerns in general. And if we say that syntax highlighting in editors can eliminate this kind of problems, that reasoning of course would apply to the partial application case as well. |
@sarimarton Not from a formal syntactic perspective, and the object context is much harder to miss (as it's explicit from the start). I don't see much different than looking at a large callback body and accidentally mistaking it as a block. |
Looks like there are ASI hazard in this code:
|
@mayorovp Already known. 👍 (But thanks for the heads up, anyways! 😉) |
@isiahmeadows you message contains no code. I constructed the counterexample to that argument:
|
@mayorovp Okay...I probably should've linked to @rbuckton's comment instead. But your example would still not be ambiguous, and the ASI hazard is the same as in his. It would be parsed as |
Wouldn't it be much more in the spirit of JavaScript to actually use a keyword operator? Here, I'm using const partiallyAppliedFn = partial foo(x++, y(g, h, i, j), m * n, "hello", bar, ...)
const countOfBooksByAuthor = library
|> partial descendantsAndSelf(?)
|> partial filter(?, node => node.category === "programming")
|> partial groupBy(?, node => node.author); Yea we'd be doing more typing but it's just so much more declarative. After all, this is the same reason we have |
@btoo I'm not sure a keyword provides any benefit that a sigil doesn't. More to the point, any solution that provides no material benefit over arrow functions is pointless. (Yours would really be more verbose than arrow functions, so very few would actually use it.) |
@isiahmeadows like I said, it is only ever more verbose when compared with the single-argument shorthand for arrow functions, so this may seem less convenient for something like the pipeline operator, but really this is a price I'm more than willing to pay if it means more expressive code. By the way, Clojure seems to be ok with it - but if you really do care about typing a couple more letters, this could be remedied with a word like |
@btoo That's slightly different, and functions more like JavaScript's |
If sigil is required, I suggest reuse |
I am closing this issue as I do not believe a prefix sigil is strictly necessary given the current eager-evaluation and ArgumentList-only semantics. The only reason I believe a sigil might be warranted would be in the following situations:
If either of these situations becomes apparent, I will consider reopening this issue for further discussion. |
It was brought up by @waldemarhorwat at the September meeting that it can be confusing if you change this:
To this:
As it requires the developer to follow the entire argument list to see the
...
to understand this isn't a function call but is rather a partial application.He suggested we consider some type of syntactic marker either before the call or before the argument list (i.e.
□foo(?)
orfoo□(?)
, where□
is some as-yet-specified token).He also indicated that there is no mechanism to partially apply a call with no arguments, which such a token would address.
The text was updated successfully, but these errors were encountered: