[plt-scheme] ifndef in PLT?

From: Dmitry Lizorkin (lizorkin at ispras.ru)
Date: Thu Oct 6 01:40:51 EDT 2005

Hello!

At macro-expansion time, I need to determine whether a given identifier is
defined. I failed to find any standard PLT facility for this purpose in the
documentation.

I thought of the following solution:

(require (lib "defmacro.ss"))

; Return `body' if `id' is not defined
(define-macro (ifndef id body)
  (with-handlers
      (((lambda (x) #t)
        (lambda (x) `,body)))
    (eval id)
    #t))

(ifndef
 string-upcase
 (define (string-upcase str) ...))

It works; however, I do not like calling `eval' in the macro body.
Could you suggest a more elegant solution?

Thank you,
Dmitry





Posted on the users mailing list.