chicken-users
[Top][All Lists]
Advanced

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

Re: [Chicken-users] how to use define-macro to...


From: Alex Shinn
Subject: Re: [Chicken-users] how to use define-macro to...
Date: Thu, 20 Dec 2007 21:01:06 +0900

On Dec 20, 2007 8:35 PM, minh thu <address@hidden> wrote:
>
> 1/
> I'd like to "repeat" this code for a lot of operators (not just + as
> in the following).

(define-syntax shadow
  (syntax-rules ()
    ((shadow op old-op)
     (begin
      (define old-op op)
      (define (op a b)
        (if (or (instance-of? a <behavior>) (instance-of b? <behavior>))
            (create-behavior (list a b) old-op)
            (old-op a b)))))))

(shadow + old+)
(shadow - old-)
(shadow * old*)
... etc.

That's if you want the old operator visible - you could also use a temp.

> 2/
>
> But it's boring; I would prefer have a "debug" macro instead :

(define-syntax eval-when-defined
  (syntax-rules ()
    ((eval-when-defined sym expr)
     (cond-expand (sym expr) (else (noop))))))

(define-syntax debug
  (syntax-rules ()
    ((debug expr)
     (eval-when-defined debug-behaviors expr))))

define-macro is fundamentally broken.

And for these types of macros syntax-rules is actually
simpler - you're just dealing with templates.

-- 
Alex




reply via email to

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