-
Notifications
You must be signed in to change notification settings - Fork 90
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
New syntax (probably again) #136
Comments
There's already #116 about how to meet desires for both blocks and expressions as case bodies (well, specifically for how to re-introduce the expression case). Making the cases syntactically identical to arrow functions might be a bit confusing since you wouldn't be able to extract the case out into a function and refer to it by identifier. I kinda like the parameter-list-style syntax for the pattern though.. |
Yeah, arrow syntax could be conflict with declared functions inside case body, so I switching to |
In current proposal |
yes, I mentioned about replacing statement with expression. I don't see any problems with that. Semantics with expression in JavaScript don't require explicitly return some value and just automatically return |
I'll elaborate. I don't see how your proposal helps in
In fact parser doesn't know syntax from your proposal at all. Also it interferes with do expressions proposal.
Omitting |
Look at this part: .. {
({ x, y, z }) -> Math.sqrt(x ** 2 + y ** 2 + z ** 2),
} It pretty the same as: {
'0': ({ x, y, z }) => Math.sqrt(x ** 2 + y ** 2 + z ** 2),
} Which already valid and parsed. Of course
Yes. Semantics in |
Also const getLength = vector =>
do (vector) {
({ x, y, z }) -> Math.sqrt(x ** 2 + y ** 2 + z ** 2), // comma operator?
({ x, y }) -> Math.sqrt(x ** 2 + y ** 2),
() -> vector.length,
} |
comma is operator the same as |
Could |
yes, I think |
Yes, it's the same issue as in tc39/proposal-class-fields#7 (comment). Still, using |
The comma is operator and can be inside expressions. The semicolon is not an operator and cannot be used inside an expression. It is used as part of JavaScript syntax to mark the end of an expression that is being treated as a statement and using as terminator instead |
I'm inclined to do this the way #116 proposes tbh. |
@zkat but what about switching from let a = ...
switch (b) {
case (a): case (a) {
when 1 -> ...
whrn 2 -> ...
}
}
|
I still don't agree with that because semantically comma operator has completely another meaning than semicolon and comma usage in your examples is error prone and unintuitive IMO. |
@chicoxyzzy @MaxGraey
(If it were ambiguous, it would've been caught by now and nobody would still be pushing it forward.) |
Sorry, by ambiguity I mean that it's not readable enough when combined with case clause from switch statement as in example above. It's not parsable by humans nor machines, so probably I chose the wrong word 🙂 |
I did understand the "visually ambiguous" bit - I was just responding to the "technically ambiguous" claim by showing it was not. Visually, I'm not convinced it's as ambiguous as you're making it seem, simply because it lacks that colon. Missing the colon before anything other than an open curly brace is already enough to get runtimes to yell at you if you're not already using a linter shouting even louder, so I find it unlikely anyone is going to forget that. A linter could warn about using a |
I imagine replacing |
@FireyFly How this could conflict with |
@MaxGraey I meant that it seems equally prone to confusion for humans as with |
Unfortunately, the |
I don't think it isn't even worth talking about reserving a new keyword. Between this and #116, I found this syntax cleaner and would honestly use it without problems. The motivations are clear and the fact that |
@tloriato It's easy, but that's not quite where you would draw the distinction. It would work more like
|
I'm not willing to conflict with |
Example of current proposal:
New proposed syntax:
Motivation:
return
for each case and also allow reusing matched result later.do
already reserved keyword. Existing parser expectdo {
, so then it come across todo (
it could try start parsing this differently. Also matching have many similarities with single iterated Dijkstra's Guarded loop and relate to do expressions proposalThoughts?
PS More examples:
worst examples with existing proposal:
same examples with new syntax:
Using as IIFE
The text was updated successfully, but these errors were encountered: