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]

Re: Using environment-bound? in macro definitions


Hello Per,

Ah! You're totally right. I thought I'll need to use the environment
instance but if I just keep a data structure (known) at syntax time, I
won't need to deal with environments at all, because 'known' will be
the environment (for my purposes).

This is the working code:

(define-for-syntax known (list))

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

(define-syntax define-bar
  (lambda (stx)
    (syntax-case stx ()
      ((define-bar a n)
       (identifier? #'a)
       (if (assoc #'a known)
           #'(set! a (cons n a))
           #'(begin
               (define-foo a)
               (set! a (cons (list n 0) a))))))))

(define-foo x)
(display x) (newline) ;; prints ()
(define-bar x 1)
(display x) (newline) ;; prints (1)


Thanks!


Duncan.


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