return when desugaring to closures

Dave Herman dherman at ccs.neu.edu
Sat Oct 11 16:33:09 PDT 2008


On Oct 11, 2008, at 7:13 PM, Mark S. Miller wrote:

> Cool! So why are we still discussing proposed let expressions and let
> blocks as distinct constructs?

I'm open to just having a single form, which is an expression whose  
body is a statement. In fact, waaaaay back (about 2 to 2.5 years ago)  
the original proposal I wrote for `let' was a single form which was an  
expression whose body was a block. And it used the completion value.  
It spun off into the let declaration form (which I personally think is  
a good thing) but without `lambda' it seemed more natural to have  
separate expression and statement forms.

I am most definitely in favor of steps towards unifying statements and  
expressions, and I think the completion value is the glue between  
them. It'll never be a perfect marriage, because some C-isms are just  
so darned imperative (e.g., switch cases requiring break; e.g., loop  
forms working via mutation), and C's expression forms are so clunky  
(e.g., ?:). But those are minor warts compared to the benefit of  
taking advantage of the completion value.

> How about just
>
>  Expression  ::= ... | lambda Formals? Block
>
> ?

Or even

     Expression ::= ... | lambda Formals? Statement

as Yuh-Ruey suggested. I don't know if that causes nasty ambiguities,  
but I'm open to it. Also, the expression-body form falls out naturally  
as an instance of ExpressionStatement.

[Hm, one ambiguity is "lambda(x)(x)" could be read as either a  
headless lambda with the body (x) being applied to (x) or as a headful  
lambda with the body (x). I'm not in love with the optional formals,  
since it doesn't have Smalltalk's incredibly lightweight syntax. I  
think being able to leave off the formals list is the biggest win when  
the syntax for closures is ultra-cheap. Otherwise the savings of the  
two characters '(' ')' isn't really that important.]

Dave



More information about the Es-discuss mailing list