[plt-scheme] Comments on an alternate syntax for let?

From: Neil Van Dyke (neil at neilvandyke.org)
Date: Mon Apr 7 12:33:13 EDT 2008

Majorinc, Kazimir wrote at 04/07/2008 11:04 AM:
> What is the the advantage of
> (let ((x 0)(y 1)(z 2)) ...)
> over
> (let ()
>    (define x 0)
>    (define y 1)
>    (define z 2)
>    ...)
> except that simultaneus evaluation in the first case? What we can not 
> do with second and we can with first?

In the first, the bindings could be called simultaneous, but the 
evaluation order of of the value expressions is unspecified.

I never use internal "define" myself (as a matter of preference), so I'd 
like to address your question in terms of "let", "let*", and 
"letrec"...  I use "let" whenever I don't *need* the special properties 
of "let*" or "letrec".  Of course I could use "letrec*" almost all the 
time, but, by using "let" as often as practical, I document for human 
readers of the code that I'm not relying on order of evaluation, I'm not 
referring to earlier bindings in value expressions, and I'm not binding 
mutually recursive closures.  So, by this rationale... if internal 
"define"s are like "letrec*", then they at least are to be avoided in 
the cases that "letrec*" would be avoided, which is most cases.

(Please note that I'm not arguing against the use of internal "define" 
in student languages, where avoiding syntax and subtleties is a higher 
priority than in non-student languages.)

I've thought that one neat Check Syntax feature of DrScheme for 
beginning Scheme programmers would be to tell the programmer when s/he 
is using "let*" or "letrec" but "let" would work, and why.


Posted on the users mailing list.