chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Chicken-users] New bindings egg with define-macro and macro-rules


From: Juergen Lorenz
Subject: [Chicken-users] New bindings egg with define-macro and macro-rules
Date: Tue, 17 Nov 2015 16:58:22 +0100
User-agent: Mutt/1.5.23+89 (0255b37be491) (2014-03-12)

Hi all,

I just uploaded version 4.0 of my bindings egg. It offers besides a long
list of binding macros (in particular bind, which is more or less Common
Lisp's destructuring-bind, and bind-case which is similar to the match
macro) some procedural macro-writing macros based on them and -- of
course -- on implicit renaming. For example, a hygienic
define-macro is provided, as well as macro-rules, which is a procedural
variant of syntax-rules, as easy to use as the latter but much more
powerfull.

To wet your appetite, here is a version of letrec with define-macro:

  (define-macro (my-letrec pairs . body)
    (let ((vars (map car pairs))
          (vals (map cadr pairs))
          (aux (map (lambda (x) (gensym)) pairs)))
      `(let ,(map (lambda (var) `(,var #f)) vars)
         (let ,(map (lambda (a v) `(,a ,v)) aux vals)
           ,@(map (lambda (v e) `(set! ,v ,e)) vars vals)
           ,@body))))

Compare this with the syntax-rules definition in the R5RS standard.

And here are two examples of macro-rules, an anaphoric version of
lambda, injecting the symbol self, so that it can be used anonymously
even in the recursive case, and a verbose if. These examples show, how
injections and keyword-symbols are declared in the syntax:

  (define-syntax alambda
    (macro-rules self ()
      ((_ args xpr . xprs)
       `(letrec ((,self (lambda ,args ,xpr ,@xprs)))
          ,self))))
                                        
  (define-syntax vif
    (macro-rules (then else)
      ((_ test (then . xprs) (else . yprs))
       `(if ,test
          (begin ,@xprs)
          (begin ,@yprs)))))

This version, 4.0, is completely rewritten and restructured, with only
some small changes in the interface. The helper module of former
versions has been removed and syntax-rules calls are replaced by
macro-rules or define-macro.

Have fun to try this egg ...

Juergen

-- 

Dr. Juergen Lorenz
Flensburger Str. 12
10557 Berlin

Attachment: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]