From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Andy Wingo Newsgroups: gmane.lisp.guile.devel Subject: Re: syntax-local-binding Date: Thu, 19 Jan 2012 12:41:13 +0100 Message-ID: <87sjjbvs12.fsf@pobox.com> References: <874nvw99za.fsf@pobox.com> <87zkdo7uf5.fsf@pobox.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1326980373 28111 80.91.229.12 (19 Jan 2012 13:39:33 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 19 Jan 2012 13:39:33 +0000 (UTC) To: guile-devel Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Thu Jan 19 14:39:28 2012 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1RnsD9-0002na-Jf for guile-devel@m.gmane.org; Thu, 19 Jan 2012 14:39:27 +0100 Original-Received: from localhost ([::1]:49636 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RnsD9-0001H0-3o for guile-devel@m.gmane.org; Thu, 19 Jan 2012 08:39:27 -0500 Original-Received: from eggs.gnu.org ([140.186.70.92]:40053) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RnsCy-0001Gh-TO for guile-devel@gnu.org; Thu, 19 Jan 2012 08:39:24 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RnsCt-0006Cg-8l for guile-devel@gnu.org; Thu, 19 Jan 2012 08:39:16 -0500 Original-Received: from a-pb-sasl-sd.pobox.com ([74.115.168.62]:64563 helo=sasl.smtp.pobox.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RnsCt-0006Cc-2k for guile-devel@gnu.org; Thu, 19 Jan 2012 08:39:11 -0500 Original-Received: from sasl.smtp.pobox.com (unknown [127.0.0.1]) by a-pb-sasl-sd.pobox.com (Postfix) with ESMTP id DDD3963AB for ; Thu, 19 Jan 2012 08:39:10 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to :subject:references:date:in-reply-to:message-id:mime-version :content-type; s=sasl; bh=90IXOZqEAsZbSMdnjiXoS2ni1JY=; b=wR2Ipi o+eucFNbROeEuQVvhxkxu1di5uYSBGbdLg+YJt4XZfLIO62AEo/xUlfSboaPlzlF UYPd8+vzEt34hpRDNl4e9S6o0AWEIyFY58F4F5U2lWJmrh4aMk/e/dSmQIQ5U6Mo LOY7KGl11B7ev1O/s1CqGvdHzCykCC+ka5CqY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=pobox.com; h=from:to:subject :references:date:in-reply-to:message-id:mime-version :content-type; q=dns; s=sasl; b=nAM9VFfrmWYbKIXNVfSgaN7SdVLsYJCS sIi//8CSV+5d4WZQpDG2GUtf7I62KnyQjkYsg89SucbfbfBYrAPVF/PSSgpYTWiF m3nKUPxcNSZ3mFfR9epgFnNdEukPtVotUH1iZLzS/YR7g2IeU34RSqtkIAbUhh0+ l4OqU9wjSXY= Original-Received: from a-pb-sasl-sd.pobox.com (unknown [127.0.0.1]) by a-pb-sasl-sd.pobox.com (Postfix) with ESMTP id D7B0D63AA for ; Thu, 19 Jan 2012 08:39:10 -0500 (EST) Original-Received: from badger (unknown [90.164.198.39]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by a-pb-sasl-sd.pobox.com (Postfix) with ESMTPSA id 1BDAD63A9 for ; Thu, 19 Jan 2012 08:39:09 -0500 (EST) In-Reply-To: <87zkdo7uf5.fsf@pobox.com> (Andy Wingo's message of "Sun, 15 Jan 2012 18:22:06 +0100") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux) X-Pobox-Relay-ID: F7845A16-42A2-11E1-AF91-65B1DE995924-02397024!a-pb-sasl-sd.pobox.com X-detected-operating-system: by eggs.gnu.org: Solaris 10 (beta) X-Received-From: 74.115.168.62 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:13586 Archived-At: Hello, I have now pushed an implementation of syntax-local-binding to stable-2.0, with the following documentation. In the spirit of Eli's note on Racket's syntax-local-value, it also works with identifiers that are bound at the module level or the top level. Comments and patches welcome. Cheers, Andy -- Scheme Procedure: syntax-local-binding id Resolve the identifer ID, a syntax object, within the current lexical environment, and return two values, the binding type and a binding value. The binding type is a symbol, which may be one of the following: `lexical' A lexically-bound variable. The value is a unique token (in the sense of `eq?') identifying this binding. `macro' A syntax transformer, either local or global. The value is the transformer procedure. `pattern-variable' A pattern variable, bound via syntax-case. The value is an opaque object, internal to the expander. `displaced-lexical' A lexical variable that has gone out of scope. This can happen if a badly-written procedural macro saves a syntax object, then attempts to introduce it in a context in which it is unbound. The value is `#f'. `global' A global binding. The value is a pair, whose head is the symbol, and whose tail is the name of the module in which to resolve the symbol. `other' Some other binding, like `lambda' or other core bindings. The value is `#f'. This is a very low-level procedure, with limited uses. One case in which it is useful is to build abstractions that associate auxiliary information with macros: (define aux-property (make-object-property)) (define-syntax-rule (with-aux aux value) (let ((trans value)) (set! (aux-property trans) aux) trans))) (define-syntax retrieve-aux (lambda (x) (syntax-case x () ((x id) (call-with-values (lambda () (syntax-local-binding #'id)) (lambda (type val) (with-syntax ((aux (datum->syntax #'here (and (eq? type 'macro) (aux-property val))))) #''aux))))))) (define-syntax foo (with-aux 'bar (syntax-rules () ((_) 'foo)))) (foo) => foo (retrieve-aux foo) => bar `syntax-local-binding' must be called within the dynamic extent of a syntax transformer; to call it otherwise will signal an error. -- http://wingolog.org/