From: Per Bothner <per@bothner.com>
To: Duncan Mak <duncanmak@gmail.com>,
kawa mailing list <kawa@sourceware.org>
Subject: Re: Using environment-bound? in macro definitions
Date: Tue, 03 Jan 2017 15:46:00 -0000 [thread overview]
Message-ID: <f506008b-51b8-5d42-aaa0-49eba2a5d7a3@bothner.com> (raw)
In-Reply-To: <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/
next prev parent reply other threads:[~2017-01-03 15:46 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-02 23:30 Duncan Mak
2017-01-03 15:46 ` Per Bothner [this message]
2017-01-03 22:06 ` Duncan Mak
2017-01-04 2:41 ` Duncan Mak
2017-01-04 4:33 ` Per Bothner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=f506008b-51b8-5d42-aaa0-49eba2a5d7a3@bothner.com \
--to=per@bothner.com \
--cc=duncanmak@gmail.com \
--cc=kawa@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).