unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Andy Wingo <wingo@pobox.com>
To: guile-devel <guile-devel@gnu.org>
Subject: Re: syntax-local-binding
Date: Thu, 19 Jan 2012 12:41:13 +0100	[thread overview]
Message-ID: <87sjjbvs12.fsf@pobox.com> (raw)
In-Reply-To: <87zkdo7uf5.fsf@pobox.com> (Andy Wingo's message of "Sun, 15 Jan 2012 18:22:06 +0100")

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/



  reply	other threads:[~2012-01-19 11:41 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-15 17:00 syntax-local-binding Andy Wingo
2012-01-15 17:22 ` syntax-local-binding Andy Wingo
2012-01-19 11:41   ` Andy Wingo [this message]
2012-01-20 20:26     ` syntax-local-binding Mark H Weaver
2012-01-20 21:23       ` syntax-local-binding Andy Wingo
2012-01-20 22:03         ` syntax-local-binding Mark H Weaver
2012-01-22  0:03           ` syntax-local-binding Ludovic Courtès
2012-01-23 16:05           ` syntax-local-binding Andy Wingo
2012-01-23 21:03             ` syntax-local-binding Mark H Weaver
2012-01-23 22:19               ` syntax-local-binding Andy Wingo
2012-01-24  2:11                 ` syntax-local-binding Mark H Weaver
2012-01-24 11:42                   ` syntax-local-binding Andy Wingo
2012-01-24 17:29                     ` syntax-local-binding Noah Lavine
2012-01-24 10:30                 ` syntax-local-binding Peter TB Brett
2012-01-24 10:38                   ` syntax-local-binding David Kastrup
2012-01-24 11:26                   ` syntax-local-binding Andy Wingo
2012-01-24 13:25                     ` syntax-local-binding Mark H Weaver
2012-01-24 20:28                       ` mark uniqueness (Was: Re: syntax-local-binding) Andy Wingo
2012-01-25  0:26                         ` mark uniqueness Mark H Weaver
2012-01-25  9:02                           ` Andy Wingo
2012-01-24 21:22                       ` syntax-local-binding Andy Wingo
2012-01-25  2:30                         ` syntax-local-binding Mark H Weaver
2012-01-25  7:49                           ` syntax-local-binding Stefan Israelsson Tampe
2012-01-25 11:18                           ` syntax-local-binding Andy Wingo
2012-01-25 13:18                           ` syntax-local-binding Ludovic Courtès
2012-01-25 18:08                             ` syntax-local-binding Mark H Weaver
2012-01-26 11:21                             ` syntax-local-binding Andy Wingo

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

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87sjjbvs12.fsf@pobox.com \
    --to=wingo@pobox.com \
    --cc=guile-devel@gnu.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).