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

From: Neil Van Dyke (neil at neilvandyke.org)
Date: Mon Apr 7 00:49:38 EDT 2008

Grant Rettke wrote at 04/06/2008 11:58 PM:
> In the comp.lang.lisp post [The syntax of LET] by Jeff M, hed wondered
> why the syntax of let wasn't simpler, like; (let (x 0 y 1 z 2) (+ x y
> z)). Someone proposed he write a macro.
>   

Perhaps they wanted to leave a good exercise for learning syntax 
extensions. :)

> I wrote a macro for Scheme. May you please evaluate it? (no pun intended)
>
> Here it is:
>
> (define-syntax (my-let stx)
>   (syntax-case stx ()
>     [(_ (var val rest ...) exp1 exp2 ...)
>      #'(let ([var val])
>          (_ (rest ...) exp1 exp2 ...))]
>     [(_ () exp1 exp2 ...)
>      #'(let ()
>          exp1 exp2 ...)]
>     [(_)
>      ((raise-syntax-error #f "at least one expression in the body is
> required" stx))]
>     [(_ (var) exp1 exp2 ...)
>      (raise-syntax-error #f "binding list must be even" (syntax var))]))
>   

The semantics of "my-let" here is not that of "let".  "let" bindings 
should be simultaneous.  Looks more like "let*", in which the bindings 
are done in sequence and earlier bindings are accessible to subsequent 
bindings.  See the R5RS documentation for more on the difference between 
"let" and  "let*"  And then look at "letrec" for another semantics issue.

Regarding whether the strictly unnecessary parentheses in "let" are a 
good idea, I think they cue the human reader of the code to the 
syntactic structure.  This isn't that useful when one is binding three 
one-letter symbols to three one-digit values, but I think it *is* useful 
when you start to get larger value expressions.

A related fun exercise is to come up with an elegant, 
backwards-compatible extension to "let" to support multiple-values.

I'm not wholly satisfied with my own last attempt, and I'm not sure 
supporting rest arguments for multiple-value "let" is even a good idea.
http://srfi.schemers.org/srfi-71/mail-archive/msg00012.html
http://srfi.schemers.org/srfi-71/mail-archive/msg00013.html


-- 
http://www.neilvandyke.org/


Posted on the users mailing list.