chicken-users
[Top][All Lists]
Advanced

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

Re: [Chicken-users] hygienic egg PORT-A-MANIA!


From: Tobia Conforto
Subject: Re: [Chicken-users] hygienic egg PORT-A-MANIA!
Date: Mon, 25 Aug 2008 19:00:30 +0200

Alan Post wrote:
(define-macro (char->number ch)
 `(- (char->integer ,ch)
     (char->integer #\0)))

(define-macro (0= n)
 `(= 0 ,n))

(define-macro (begin0 form . forms)
 (let ((var (gensym)))
   `(let ((,var ,form)) ,@forms ,var)))

If |define-macro| is no longer around, how would the above forms be written?

With Scheme's standard high-level, hygienic macros, that Chicken now supports natively:

(define-syntax char->number
  (syntax-rules ()
    ((char->number ch)
     (- (char->integer ch)
        (char->integer #\0)))))

(define-syntax 0=
  (syntax-rules ()
    ((0= n)
     (= 0 n))))

(define-syntax begin0
  (syntax-rules ()
    ((begin0 form forms ...)
     (let ((temp form))
       forms ...
       temp))))

This is kind of the whole point of the hygienic branch ;-)

Notice how more readable they are, without commas and stuff. Yes, the "..." is very clever and does what you would expect and no, temp won't collide with *any* other variable named temp, whatsoever. No more gensym and quasiquote!

On the other hand, why are these written as macros in the first place?


Tobia




reply via email to

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