guile-devel
[Top][All Lists]
Advanced

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

syntax-locally-bound-identifiers, local-eval


From: Andy Wingo
Subject: syntax-locally-bound-identifiers, local-eval
Date: Fri, 20 Jan 2012 13:33:29 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux)

Hello,

Here are a couple of patches.  The first implements a new helper,
syntax-locally-bound-identifiers, documented thusly:

 -- Scheme Procedure: syntax-locally-bound-identifiers id
     Return a list of identifiers that were visible lexically when the
     identifier ID was created, in order from outermost to innermost.

     This procedure is intended to be used in specialized procedural
     macros, to provide a macro with the set of bound identifiers that
     the macro can reference.

     As a technical implementation detail, the identifiers returned by
     `syntax-locally-bound-identifiers' will be anti-marked, like the
     syntax object that is given as input to a macro.  This is to
     signal to the macro expander that these bindings were present in
     the original source, and do not need to be hygienically renamed,
     as would be the case with other introduced identifiers.  See the
     discussion of hygiene in section 12.1 of the R6RS, for more
     information on marks.

          (define-syntax lexicals
            (lambda (x)
              (syntax-case x ()
                ((lexicals) #'(lexicals lexicals))
                ((lexicals scope)
                 (with-syntax (((id ...)
                                (filter (lambda (x)
                                          (eq? (syntax-local-binding x) 
'lexical))
                                        (syntax-locally-bound-identifiers 
#'scope))))
                     #'(list (cons 'id id) ...))))))

          (let* ((x 10) (x 20)) (lexicals))
          => ((x . 10) (x . 20))

The second implements local-eval, in a separate module.

There are a couple of notable changes in this version: firstly, it
correctly preserves the scope resolution order of scopes between normal
lexicals, macros, and pattern variables.  It includes all of the
original marks of all identifiers.  It also wraps pattern variables
now, and doesn't re-box normal lexicals.

Thoughts?  I will commit them tomorrow if there are no objections to the
semantics.

Thanks very much to Mark for his great work on the patches that inspired
these ones, even though he might wish to disavow this particular
implementation strategy :-)

Regards,

Andy
-- 
http://wingolog.org/



reply via email to

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