let* is the new var

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

let* is the new var

Jon Zeppieri-2
Was let*, possibly under some other name, ever discussed/proposed?
For let definitions, I think the following is supposed to work:

{
  let x = n;
  let y = foo(x);
  ...
}

That is, x and y should be bound sequentially, not in parallel, right?
 (An example at
http://wiki.ecmascript.org/doku.php?id=proposals:block_expressions
strongly suggests this, anyway.)  Doesn't work in the RI, but I assume
this is a bug.

However, there's no good way to do this for let expressions.  (Having
to nest the expressions leads to cluttered code.)  Also, since the
motto for let was "let is the new var," it should be mentioned that
var binds left-to-right.
_______________________________________________
Es4-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es4-discuss
Reply | Threaded
Open this post in threaded view
|

Re: let* is the new var

Dave Herman-2
> Was let*, possibly under some other name, ever discussed/proposed?
> For let definitions, I think the following is supposed to work:
>
> {
>   let x = n;
>   let y = foo(x);
>   ...
> }
>
> That is, x and y should be bound sequentially, not in parallel, right?

Neither, actually -- for let declarations. In your example, both x and y
are bound in the entire block -- this is hoisting just like `var',
except it's only hoisted to the top of the block instead of the
function. This might sound surprising, but this means that it's letrec
rather than let*.

For let expressions and let statements, though, I agree with you. I
think we ought to have let* semantics, and as you say I think the RI
currently implements let semantics.

Dave

_______________________________________________
Es4-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es4-discuss
Reply | Threaded
Open this post in threaded view
|

Re: let* is the new var

Jon Zeppieri-2
On Tue, Mar 25, 2008 at 6:17 PM, Dave Herman <[hidden email]> wrote:
>
>  Neither, actually -- for let declarations. In your example, both x and y
>  are bound in the entire block -- this is hoisting just like `var',
>  except it's only hoisted to the top of the block instead of the
>  function. This might sound surprising, but this means that it's letrec
>  rather than let*.

Is it actually letrec, or is it letrec*?  The example I referred to
(from the proposal page) would require letrec* semantics:

===
if (x > y)
   {
      let const k = 37;
      let gamma : int = 12.7 + k;
      let i = 10;
      let function f(n) { return (n/3)+k; }
      return f(gamma) + f(i);
   }
===

>
>  For let expressions and let statements, though, I agree with you. I
>  think we ought to have let* semantics, and as you say I think the RI
>  currently implements let semantics.

It's not just the RI; the official proposal is very specific about let
semantics.

-Jon


>
>  Dave
>
>
_______________________________________________
Es4-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es4-discuss
Reply | Threaded
Open this post in threaded view
|

Re: let* is the new var

Dave Herman-2
> Is it actually letrec, or is it letrec*?  The example I referred to
> (from the proposal page) would require letrec* semantics:

Let's not go too far with the Scheme analogies, since we're not talking
about Scheme. :) The idea is just like var-hoisting, only the hoisting
goes to the top of the nearest block, not the nearest function. Just
like var-hoisting, the initializer expressions are just assignments that
happen exactly where you wrote them. So indeed, like letrec*, the
initializers are evaluated in order from top to bottom.

> It's not just the RI; the official proposal is very specific about let
> semantics.

This is a detail that we should stamp out, I agree. I'll look for a trac
ticket and file one if there isn't one.

Dave
_______________________________________________
Es4-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es4-discuss
Reply | Threaded
Open this post in threaded view
|

Re: let* is the new var

Dave Herman-2
Created as ticket #375:

http://bugs.ecmascript.org/ticket/375

Dave

_______________________________________________
Es4-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es4-discuss
Reply | Threaded
Open this post in threaded view
|

Re: let* is the new var

P T Withington
This conversation makes me ask, what is the semantics of var in a  
class declaration?  E.g.:

class ... {
   function foo ...
   var fooAlias = foo;

   var bar = 42;
   var bletch = bar + 1;

etc.

Same rules?  All slots created at the top of the block and  
initializations executed in order?  I'm particularly interested in the  
case of creating an alias to a function.

On 2008-03-25, at 19:03 EDT, Dave Herman wrote:

> Created as ticket #375:
>
> http://bugs.ecmascript.org/ticket/375
>
> Dave
>
> _______________________________________________
> Es4-discuss mailing list
> [hidden email]
> https://mail.mozilla.org/listinfo/es4-discuss

_______________________________________________
Es4-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es4-discuss
Reply | Threaded
Open this post in threaded view
|

RE: let* is the new var

Lars Hansen-3
Don't remember this ever coming up; I always assumed it would be like
for ES3 code (scopes of names are the entire block; functions are
initialized first; then variables in order).

--lars

> -----Original Message-----
> From: [hidden email]
> [mailto:[hidden email]] On Behalf Of P T Withington
> Sent: 26. mars 2008 05:48
> To: Dave Herman
> Cc: es4-discuss Discuss; Jon Zeppieri
> Subject: Re: let* is the new var
>
> This conversation makes me ask, what is the semantics of var
> in a class declaration?  E.g.:
>
> class ... {
>    function foo ...
>    var fooAlias = foo;
>
>    var bar = 42;
>    var bletch = bar + 1;
>
> etc.
>
> Same rules?  All slots created at the top of the block and
> initializations executed in order?  I'm particularly
> interested in the case of creating an alias to a function.
>
> On 2008-03-25, at 19:03 EDT, Dave Herman wrote:
> > Created as ticket #375:
> >
> > http://bugs.ecmascript.org/ticket/375
> >
> > Dave
> >
> > _______________________________________________
> > Es4-discuss mailing list
> > [hidden email]
> > https://mail.mozilla.org/listinfo/es4-discuss
>
> _______________________________________________
> Es4-discuss mailing list
> [hidden email]
> https://mail.mozilla.org/listinfo/es4-discuss
>
_______________________________________________
Es4-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es4-discuss
Reply | Threaded
Open this post in threaded view
|

RE: let* is the new var

Jeff Dyer
Let's use 866 7052554, 6608431. dialing now...

> -----Original Message-----
> From: [hidden email] [mailto:es4-discuss-
> [hidden email]] On Behalf Of Lars Hansen
> Sent: Wednesday, April 02, 2008 2:49 PM
> To: P T Withington; Dave Herman
> Cc: es4-discuss Discuss; Jon Zeppieri
> Subject: RE: let* is the new var
>
> Don't remember this ever coming up; I always assumed it would be like
> for ES3 code (scopes of names are the entire block; functions are
> initialized first; then variables in order).
>
> --lars
>
> > -----Original Message-----
> > From: [hidden email]
> > [mailto:[hidden email]] On Behalf Of P T Withington
> > Sent: 26. mars 2008 05:48
> > To: Dave Herman
> > Cc: es4-discuss Discuss; Jon Zeppieri
> > Subject: Re: let* is the new var
> >
> > This conversation makes me ask, what is the semantics of var
> > in a class declaration?  E.g.:
> >
> > class ... {
> >    function foo ...
> >    var fooAlias = foo;
> >
> >    var bar = 42;
> >    var bletch = bar + 1;
> >
> > etc.
> >
> > Same rules?  All slots created at the top of the block and
> > initializations executed in order?  I'm particularly
> > interested in the case of creating an alias to a function.
> >
> > On 2008-03-25, at 19:03 EDT, Dave Herman wrote:
> > > Created as ticket #375:
> > >
> > > http://bugs.ecmascript.org/ticket/375
> > >
> > > Dave
> > >
> > > _______________________________________________
> > > Es4-discuss mailing list
> > > [hidden email]
> > > https://mail.mozilla.org/listinfo/es4-discuss
> >
> > _______________________________________________
> > Es4-discuss mailing list
> > [hidden email]
> > https://mail.mozilla.org/listinfo/es4-discuss
> >
> _______________________________________________
> Es4-discuss mailing list
> [hidden email]
> https://mail.mozilla.org/listinfo/es4-discuss
_______________________________________________
Es4-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es4-discuss
Reply | Threaded
Open this post in threaded view
|

RE: let* is the new var

Jeff Dyer
Oops. Never mind :)

Jd

> -----Original Message-----
> From: [hidden email] [mailto:es4-discuss-
> [hidden email]] On Behalf Of Jeff Dyer
> Sent: Wednesday, April 02, 2008 3:06 PM
> To: Lars Hansen; P T Withington; Dave Herman
> Cc: es4-discuss Discuss; Jon Zeppieri
> Subject: RE: let* is the new var
>
> Let's use 866 7052554, 6608431. dialing now...
>
> > -----Original Message-----
> > From: [hidden email] [mailto:es4-discuss-
> > [hidden email]] On Behalf Of Lars Hansen
> > Sent: Wednesday, April 02, 2008 2:49 PM
> > To: P T Withington; Dave Herman
> > Cc: es4-discuss Discuss; Jon Zeppieri
> > Subject: RE: let* is the new var
> >
> > Don't remember this ever coming up; I always assumed it would be
like
> > for ES3 code (scopes of names are the entire block; functions are
> > initialized first; then variables in order).
> >
> > --lars
> >
> > > -----Original Message-----
> > > From: [hidden email]
> > > [mailto:[hidden email]] On Behalf Of P T
Withington

> > > Sent: 26. mars 2008 05:48
> > > To: Dave Herman
> > > Cc: es4-discuss Discuss; Jon Zeppieri
> > > Subject: Re: let* is the new var
> > >
> > > This conversation makes me ask, what is the semantics of var
> > > in a class declaration?  E.g.:
> > >
> > > class ... {
> > >    function foo ...
> > >    var fooAlias = foo;
> > >
> > >    var bar = 42;
> > >    var bletch = bar + 1;
> > >
> > > etc.
> > >
> > > Same rules?  All slots created at the top of the block and
> > > initializations executed in order?  I'm particularly
> > > interested in the case of creating an alias to a function.
> > >
> > > On 2008-03-25, at 19:03 EDT, Dave Herman wrote:
> > > > Created as ticket #375:
> > > >
> > > > http://bugs.ecmascript.org/ticket/375
> > > >
> > > > Dave
> > > >
> > > > _______________________________________________
> > > > Es4-discuss mailing list
> > > > [hidden email]
> > > > https://mail.mozilla.org/listinfo/es4-discuss
> > >
> > > _______________________________________________
> > > Es4-discuss mailing list
> > > [hidden email]
> > > https://mail.mozilla.org/listinfo/es4-discuss
> > >
> > _______________________________________________
> > Es4-discuss mailing list
> > [hidden email]
> > https://mail.mozilla.org/listinfo/es4-discuss
> _______________________________________________
> Es4-discuss mailing list
> [hidden email]
> https://mail.mozilla.org/listinfo/es4-discuss
_______________________________________________
Es4-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es4-discuss
Reply | Threaded
Open this post in threaded view
|

Re: let* is the new var

Michael O'Brien-4
In reply to this post by Lars Hansen-3
We define the slots for vars and functions first at the top of the block
and do initializations in-order where they reside in the code flow. So:

class XX {
        function foo ...

        // fooAlias exists here but is undefined
        var fooAlias = foo

        // fooAlias is now initialized
}


Michael


On Apr 2, 2008, at 2:49 PM, Lars Hansen wrote:

> Don't remember this ever coming up; I always assumed it would be like
> for ES3 code (scopes of names are the entire block; functions are
> initialized first; then variables in order).
>
> --lars
>
>> -----Original Message-----
>> From: [hidden email]
>> [mailto:[hidden email]] On Behalf Of P T Withington
>> Sent: 26. mars 2008 05:48
>> To: Dave Herman
>> Cc: es4-discuss Discuss; Jon Zeppieri
>> Subject: Re: let* is the new var
>>
>> This conversation makes me ask, what is the semantics of var
>> in a class declaration?  E.g.:
>>
>> class ... {
>>   function foo ...
>>   var fooAlias = foo;
>>
>>   var bar = 42;
>>   var bletch = bar + 1;
>>
>> etc.
>>
>> Same rules?  All slots created at the top of the block and
>> initializations executed in order?  I'm particularly
>> interested in the case of creating an alias to a function.
>>
>> On 2008-03-25, at 19:03 EDT, Dave Herman wrote:
>>> Created as ticket #375:
>>>
>>> http://bugs.ecmascript.org/ticket/375
>>>
>>> Dave
>>>
>>> _______________________________________________
>>> Es4-discuss mailing list
>>> [hidden email]
>>> https://mail.mozilla.org/listinfo/es4-discuss
>>
>> _______________________________________________
>> Es4-discuss mailing list
>> [hidden email]
>> https://mail.mozilla.org/listinfo/es4-discuss
>>
> _______________________________________________
> Es4-discuss mailing list
> [hidden email]
> https://mail.mozilla.org/listinfo/es4-discuss

_______________________________________________
Es4-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es4-discuss