This is the mail archive of the
kawa@sourceware.org
mailing list for the Kawa project.
Re: Using environment-bound? in macro definitions
- From: Per Bothner <per at bothner dot com>
- To: Duncan Mak <duncanmak at gmail dot com>, kawa mailing list <kawa at sourceware dot org>
- Date: Tue, 3 Jan 2017 07:45:06 -0800
- Subject: Re: Using environment-bound? in macro definitions
- Authentication-results: sourceware.org; auth=none
- References: <CABgWrqrxarZFQOwB6AAqC+qyQu3fNj9fiy=S6YzewcFM4a-eDg@mail.gmail.com>
On 01/02/2017 03:29 PM, Duncan Mak wrote:
(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)
In other words, at this point:
(equal? known '(x))
test.scm:29:1: evaluating syntax transformer 'define-bar' threw
gnu.text.SyntaxException: <unknown>: unknown library (x)
That means you're evaluating (environment 'x).
The 'x is interpreted as an "environment specifier" - i.e. a library name,
and there is no such library (or class).
I think you misunderstand the 'environment' procedure. Check the Kawa and R7RS documentation.
What are you trying to do? Trying to dynamically build environment maps
is possible, but there isn't a Scheme API for it, and there are tricky interactions
between the dynamic top-level and the module-level lexical scope.
--
--Per Bothner
per@bothner.com http://per.bothner.com/