chicken-users
[Top][All Lists]
Advanced

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

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


From: minh thu
Subject: [Chicken-users] how to use define-macro to...
Date: Thu, 20 Dec 2007 12:35:23 +0100

Hi,

1/
I'd like to "repeat" this code for a lot of operators (not just + as
in the following).
How can I do that ?

(define old+ +)
(define (+ a b)
  (if (or (instance-of? a <behavior>) (instance-of? b <behavior>))
    (create-behavior (list a b) old+)
    (old+ a b)))

The problem is how to capture the old + (as old+) to use it in the redefinition.

2/
I could write the following at any place I want to print debug info.

(cond-expand
  (debug-behaviors (printf "Debugging...~N"))
  (else)

Note the particular symbol debug-behaviors.

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

(debug
  (printf "Debugging...~N"))

But I don't know how I can make it expends to nothing as in the else
clause of the
cond-expand. I use this :

(define-macro (debug rest)
  (cond-expand
    (debug-behaviors rest)
    (else '(noop))))

I have to use the noop procedure.

Also, can I write a "higher" macro to generate the "debug" one with a
particular debug-something symbol ?

Thanks,
mt




reply via email to

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