Brendan Eich wrote:
> On Oct 13, 2008, at 5:29 PM, Waldemar Horwat wrote:
> 
>> Brendan Eich wrote:
>>> On Oct 13, 2008, at 3:51 PM, Waldemar Horwat wrote:
>>>
>>>> Brendan Eich wrote:
>>>>> After some experiments, we decided for ES4 to make let and var the
>>>>> same at top level in a function or global code.
>>>>> ...
>>>> You can't do that.
>>>
>>> Which "that" do you mean?
>>
>> Turn let into var at the top level of a function body.
> 
> Ok then!
> 
> 
>>>> function f() {
>>>> x = 15;
>>>> ...
>>>> let t = some_runtime_expression;
>>>> ...
>>>> let x:t = ...
>>>> }
>>>>
>>>> What is the type of x at the beginning of the function?
>>>
>>> The example had better fail to compile.
>>
>> Because presumably the "let x:t" became "var x:t" and var can't have 
>> types?
> 
> Why can't var have a type annotation?

Because a function can have many var declarations for the same variable and 
because you can use the variable before any of the var declarations are 
evaluated.  You can work out the implications easily enough.  This has been 
brought up at meetings before.

> You can't be serious that let would be broken unless enclosed by an 
>> independent block!
> 
> I didn't say that :-P.

Actually, you did.  You wrote that you'd like let to become var (and unlike let 
as used within an independent block) if used at the top level of a function:

> After some experiments, we decided for ES4 to make let and var the  
> same at top level in a function or global code.
> 
> This helped avoid implementation pain: very long scripts on the web,  
> consisting of many statements in a row, motivate statement-wise  
> parsing and cumulative code generation, which is straightforward in  
> the absence of goto. Yet scope changes (e.g. due to a tardy rogue let  
> x; after thousands of statements the first of which uses x) require a  
> separate pass to generate the necessary block set-up code before the  
> first use of x.

What did you mean by "had better fail to compile"?  Other than the type 
annotation, there is nothing about

function f() {
  x = 15;
  ...
  var t = some_runtime_expression;
  ...
  var x:t = ...
}

that ought to fail to compile.

    Waldemar
_______________________________________________
Es-discuss mailing list
Es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to