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

From: Jos Koot (jos.koot at telefonica.net)
Date: Mon Apr 7 04:56:25 EDT 2008

I think I prefer the parentheses, for when the value expressions of the 
bindings are complicated expressions, they help avoiding mistakes, 
especially with a nice IDE that highlights subexpressions and provides 
advanced navigation. The parentheses allow you to easily jump from one 
binding to the next one.
As others already said, you made a variant of let*. Here is the let version 
(without error-detection)

(define-syntax my-let
 (syntax-rules ( )
  ((_ my-bindings body-expr0 body-expr ...)
   (my-let-aux my-bindings ( ) body-expr0 body-expr ...))))

(define-syntax my-let-aux
 (syntax-rules ( )
  ((_ ( ) (binding ...) body-expr0 body-expr ...)
   (let (binding ...) body-expr0 body-expr ...))
  ((_ (var value-expr . rest) (binding ...) body-expr0 body-expr ...)
   (my-let-aux rest (binding ... (var value-expr)) body-expr0 body-expr 
...))))

Jos

----- Original Message ----- 
From: "Grant Rettke" <grettke at acm.org>
To: "PLT-Scheme" <plt-scheme at list.cs.brown.edu>
Sent: Monday, April 07, 2008 5:58 AM
Subject: [plt-scheme] Comments on an alternate syntax for let?


> 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.
>
> 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))]))
>
> -- 
> http://www.wisdomandwonder.com/
> _________________________________________________
>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme 



Posted on the users mailing list.