[plt-scheme] Help using syntax-rules()

From: Carl Eastlund (carl.eastlund at gmail.com)
Date: Mon Mar 15 18:15:01 EDT 2010

On Mon, Mar 15, 2010 at 3:06 PM, Patrick Li <patrickli.2001 at gmail.com> wrote:
> Hi,
> I'm trying to learn Scheme's hygienic macro system, and was wondering how
> you would write something like the following:
> Say I think the current let is too verbose, and want to change it to this:
> (mylet [a 1
>            b 2
>            c 3]
>    (display a)
>    (display b)
>    (display c))
> I know how to do this using Lisp-style macros, but I'm not too familiar with
> how to use the ellipsis ... effectively.
> Thanks for your help
>   -Patrick

You can do this with ellipses with the new "syntax-parse" facility in
DrScheme 4.2.4 (and possibly a few minor versions earlier, I forget
exactly when it came out).  It allows multiple-element patterns in an
ellipsis template.

#lang scheme

(require (for-syntax syntax/parse))

(define-syntax (my-let stx)
  (syntax-parse stx
    [(_ [(~seq lhs:id rhs:expr) ...] body:expr ...)
     #'(let ([lhs rhs] ...) body ...)]))

(my-let [a 1
         b 2
         c 3]
  (list a b c))


Posted on the users mailing list.