This is the mail archive of the
kawa@sourceware.org
mailing list for the Kawa project.
Re: Using environment-bound? in macro definitions
- From: Duncan Mak <duncanmak at gmail dot com>
- To: Per Bothner <per at bothner dot com>
- Cc: kawa mailing list <kawa at sourceware dot org>
- Date: Tue, 3 Jan 2017 17:05:46 -0500
- Subject: Re: Using environment-bound? in macro definitions
- Authentication-results: sourceware.org; auth=none
- References: <CABgWrqrxarZFQOwB6AAqC+qyQu3fNj9fiy=S6YzewcFM4a-eDg@mail.gmail.com> <f506008b-51b8-5d42-aaa0-49eba2a5d7a3@bothner.com>
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.