guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

syntax-local-binding


From: Andy Wingo
Subject: syntax-local-binding
Date: Sun, 15 Jan 2012 18:00:41 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux)

Hi list,

Attached is a patch that implements a new accessor,
syntax-local-binding.  It's like syntax-local-value, but can also
determine if an identifier is a pattern var or a normal lexical.

  > (define-syntax local-binding
      (lambda (x)
        (syntax-case x ()
          ((_ id) (identifier? #'id)
           (call-with-values (lambda () (syntax-local-binding #'id))
             (lambda (x y)
               (with-syntax ((type (datum->syntax #'here x)))
                 #''type)))))))
  > (let-syntax ((x (lambda (x) 10))) (local-binding x))
  $3 = local-macro
  > (syntax-case #'(foo) () ((id) (local-binding id)))
  $4 = pattern-variable
  > (let ((x 10)) (local-binding x))
  $5 = lexical

It returns two values.  The first is a symbol, either `local-macro',
`lexical', or `pattern-variable'.  The second is specific to the type.
For local-macro it is the transformer binding.  For lexical it is the
gensym name of the lexical.  For pattern variables, it is something
opaque that identifies that pattern var.

Inspired by a patch by Stefan Israelsson Tampe.

I'm going to try to implement the-environment with this.  We'll see how
it goes!

Andy
-- 
http://wingolog.org/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]