From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 69544 invoked by alias); 3 Jan 2017 15:46:26 -0000 Mailing-List: contact kawa-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: kawa-owner@sourceware.org Received: (qmail 68545 invoked by uid 89); 3 Jan 2017 15:46:25 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.5 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 spammy=specifier X-HELO: aibo.runbox.com Received: from aibo.runbox.com (HELO aibo.runbox.com) (91.220.196.211) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 03 Jan 2017 15:46:15 +0000 Received: from [10.9.9.212] (helo=mailfront12.runbox.com) by bars.runbox.com with esmtp (Exim 4.71) (envelope-from ) id 1cORHw-0003zF-Ft; Tue, 03 Jan 2017 16:46:12 +0100 Received: from 70-36-239-8.dsl.dynamic.fusionbroadband.com ([70.36.239.8] helo=localhost.localdomain) by mailfront12.runbox.com with esmtpsa (uid:757155 ) (TLS1.2:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.82) id 1cORGw-0002tC-DK; Tue, 03 Jan 2017 16:45:10 +0100 Subject: Re: Using environment-bound? in macro definitions To: Duncan Mak , kawa mailing list References: From: Per Bothner Message-ID: Date: Tue, 03 Jan 2017 15:46:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2017-q1/txt/msg00007.txt.bz2 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 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/