Swift style syntax
Peter van der Zee
ecma at qfox.nl
Mon Oct 12 08:35:43 UTC 2015
On Mon, Oct 12, 2015 at 10:12 AM, Mohsen Azimi <me at azimi.me> wrote:
>> Your syntax is ambiguous: Should your code be interpreted as:
>>
>> let passed = objs.filter($0 => $0.passed)
>>
>> or:
>>
>> let passed = $0 => objs.filter($0.passed)
>
> I don't understand why you parsed it in the second way Claude?
It's not about the "why". He's trying to tell you this code _is_
ambiguous. The parser cares not about the why.
Look at the generic case; how could the parser know how `#0` is scoped?
There is an ambiguity and you'll need some way of telling JS what the
scope is of that `#0`. This is why there's an arrow. This is why you
need to wrap arguments in parenthesis: Disambiguation. Basically; try
to think of ways how your example should be translated. Then try to
see if they _can_ be translated differently. If they can, then you
need to think of a way to disambiguate. In the above, having no
"function offset marker" (like what the arrow is) means you cannot
know where it starts.
On a personal two cents; ugh, changes in this proposal would only lead
to even worse illegible code.
- peter
More information about the es-discuss
mailing list