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




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/


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