return when desugaring to closures

Jon Zeppieri jaz at bu.edu
Sat Oct 11 15:25:43 PDT 2008


On Sat, Oct 11, 2008 at 5:24 PM, Mark S. Miller <erights at google.com> wrote:
> On Sat, Oct 11, 2008 at 1:36 PM, Peter Michaux <petermichaux at gmail.com> wrote:
>> Simplifying
>>
>> (lambda (x = 3, y = x) (x+y))()
>>
>> to just
>>
>> let (x = 3, y = x) (x+y)
>>
>> makes it much more clear when reading code what the intention of the
>> programmer was.
>
> If the need for this case were common, that would be something. But
> how often do cases come up for which the letrec-like let declaration
> is not adequate? In hand written source, I think it's very rare.

This may be true of ES (though, really, it's impossibly to say, since
ES doesn't yet have 'let,' and we don't know what idioms will become
popular).  In Scheme, however, this sort of thing is very common,
especially in the named-let form:

(define (frob-list lst)
    (let loop ((lst lst)) ...))

... is a common idiom.  A necessary one?  Of course not.  Beside the
point, since ES has explicit iteration forms?  Maybe, but there
certainly are cases where tail recursion is more useful in ES than
'for' or 'while' iteration.  This is particularly true when
constructing closures in a loop, where each closure needs to refer to
a distinct element of the iterated sequence.  (You really don't want
to be mutating an induction variable in these cases.)


At any rate, this is, at best, a side issue.  I'd just like a
non-hoisting 'let.'  Based on what you wrote about hoisting earlier in
this thread, I'm surprised you don't want one, too.

-Jon


More information about the Es-discuss mailing list