This is the mail archive of the kawa@sourceware.org mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Using environment-bound? in macro definitions


Hello,

Here's a stripped down version of two define-form macros that I'm working on:

(require 'syntax-utils)
(define-for-syntax known (list))

(define-syntax define-foo
  (lambda (stx)
    (syntax-case stx ()
      ((define-foo a)
       (begin
         (set! known (cons #'a known))
         #'(define a (list)))))))

(define-syntax define-bar
  (lambda (stx)
    (syntax-case stx ()
      ((define-bar a n)
       (if (environment-bound? (apply environment known) #'a)
           #'(set! a (cons n a))
           #'(begin
               (define-foo a)
               (set! a (cons n a))))))))

;; (1) should expand to (define x (list)) and store x in known
(define-foo x)

;; (2) should expand to (set! x (cons 1 x)) since x was previously
;; defined (i.e. can be found in known)
(define-bar x 1)

;; (3) should expand to (begin (define-foo y) (set! y (cons 2 y)))
;; because y is not previous defined
(define-bar y 2)

When I try to run it, I get

test.scm:29:1: evaluating syntax transformer 'define-bar' threw
gnu.text.SyntaxException: <unknown>: unknown library (x)

I must be doing something wrong, is this the right approach?

Thanks!

-- 
Duncan.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]