function hoisting like var
Ingvar von Schoultz
ingvar-v-s at comhem.se
Sun Jul 27 15:41:11 PDT 2008
Brendan Eich wrote:
> On Jul 26, 2008, at 2:06 PM, Ingvar von Schoultz wrote:
>
>> How sad! It seemed such a simple and intuitive notation!
>
> Opinions vary, but all the ones I heard at the Ecma TC39 meeting
> found it neither simple nor intuitive, and some abhorred it on
> aesthetic grounds to boot.
Not simple? How is that possible?
There have been several misunderstandings. Did they spread
that far?
{{ }} is just the same as a scoping function used on ES3:
(function() { code })()
Everything works just the way I meant if you take ES3, or any
platform that does /not/ support let declarations, and make
it so that {{ }} becomes syntax sugar for the above one-shot
scoping function.
Of course, the way I think about {{ }}, I don't see it as a
function, I see it as a name-binding scope. But the scoping
effect is just that.
For me, having a single scoping block is simpler than having
two, and having a single visibility keyword is simpler than
having two. And I think my notation is /much/ simpler than
the one-shot function!
{{ code }} (function() { code })()
I do find my notation slightly ugly. But the one-shot function
is worse in my view. Charming but very kludgey.
(Thanks Igor for noticing that {{ }} are synonymous with one-shot
scoping functions. Why didn't I think of that!)
>> I think all of these would be unambiguous:
>>
>> {. code .}
>>
>> {: code :}
>>
>> {| code |}
>>
>> {[ code ]}
>>
>> [[ code ]]
>>
>> [ code ]
>
> These are either syntax errors without opt-in versioning,
Yes, and this should guarantee that they are unique.
I now have the impression that, on the client side, opt-in
by version would be necessary in any case, with any notation.
If old platforms accept the syntax, it changes existing
semantics; if they don't, it requires opt-in to avoid errors.
> or (the
> last three) do create incompatible ambiguity (consider array
> initialisers).
It seems to me that they could be disambiguated easily. I
comment on this in a reply to Igor.
> What's more, as Waldemar pointed out many threads (and too many
> words) ago, they create capture problems.
There were misunderstandings.
If there are fundamental differences in this regard between {{ }}
and one-shot scoping functions, I can't find them.
> Please work through the
> last mail I sent before replying; if some vocabulary or infelicitous
> word choice is causing any confusion, feel free to mail me privately
> and ask pointed questions. Thanks,
Thanks for the invitation. I'll certainly take you up on it
if the need or urge arises.
--
Ingvar von Schoultz
------- (My quirky use of capitals in code comes from my opinion that
reserved and predefined words should all start with lowercase, and
user-defined should all start with uppercase, because this will easily
and elegantly prevent a host of name-collision problems when things
like programming languages are upgraded with new labels.)
More information about the Es4-discuss
mailing list