return when desugaring to closures

Peter Michaux petermichaux at gmail.com
Thu Oct 9 20:57:09 PDT 2008


On Thu, Oct 9, 2008 at 4:28 PM, David Herman <dherman at ccs.neu.edu> wrote:

[snip]

> How would people feel about the declaration form being 'define'
> instead of lambda? As in:
>
>    define const(x) {
>        lambda(y) x
>    }
>
> Maybe I'm just accustomed to Scheme, but it looks awkward to me
> for the declaration form to be called lambda. Dylan also used 'define'.

I think there is a good reason for concern that may be intuitively
behind your "looks awkward". (That little voice in my head saying
"ewwwwww" is usually correct.)

>From Scheme's r5rs specification, two of the three declaration forms are

(define <variable> <expression>)
(define (<variable> <formals>) <body>)

The second form for declaring lambdas is just shorthand for

(define <variable>
    (lambda (<formals>) <body>))

So there is a reason the declaration form for lambdas uses "define":
it desugars to the first form which also uses "define". It gives a
tidy parallel syntax for both kinds of declarations.

If we try to make the same parallelism in JavaScript with "var" we would have

var <variable> = <expression>
var <variable>(<formals>) <body>

or if we use "let" we have the following parallelism

let <variable> = <expression>
let <variable>(<formals>) <body>

So in your suggestion for using "define", does "define" mean "var" or
"let" scoping of the declaration? Since it should probably mean one or
the other, it might be better to allow the declaration forms for
lambdas to just use either "var" or "let" depending how the programmer
wants the declaration scoped. If new scoping keywords appear in the
language (e.g. "our", "my") then new lambda declaration forms can use
the new keywords and scoping of various declaration forms will be
naturally parallel.

This keyword/scoping problem must already have appeared for functions
as function declarations have "var" scoping and obtaining "let"
scoping requires using something like "let a = function(){}". This is
pretty ugly for functions to have "let" scoping but the good news is
the door has been left open for real lambdas to snatch up the
available "var a(){}" and "let a(){}" syntaxes.

Peter


More information about the Es-discuss mailing list