[r6rs-discuss] bound identifier predicate
ramana.kumar at gmail.com
Sun Jun 21 03:03:42 EDT 2009
Aaron you have a good idea, but the choice for #'a is much more
important than it seems. For example, if you define your
bound-identifier? macro at the top level of some library or script
that imports (rnrs), then it will incorrectly say "define" (and other
(rnrs) imports) is unbound. You are inadvertently picking up the wrap
of the identifier #'a.
Consider this R6RS script.
(syntax-case x ()
[(k y) (identifier? #'y)
#`#,(not (free-identifier=? #'y
(datum->syntax #'a (syntax->datum #'y))))])))
(display (bound-identifier? foo)) (newline)
(display (bound-identifier? define)) (newline)
(let ((x 3)) (display (bound-identifier? x)) (newline))
The output is
The desired output is
On Sun, Jun 21, 2009 at 4:55 PM, Aaron W. Hsu<arcfide at sacrideo.us> wrote:
> Hey Ramana,
> On Sat, 20 Jun 2009 03:46:51 -0400, Ramana Kumar <ramana.kumar at gmail.com>
>> How would you write bound-identifier? in R6RS? (A function that takes
>> an identifier and returns a boolean indicating whether that identifier
>> is bound.)
> A quick read over the R6RS stuff indicates that it is similar and/or the
> same as the Chez implementation of 'free-identifier=?', which I think is
> sufficient in this case to make the 'bound-identifier?' form you desire.
>> I'm interested in
>> 1. A clearly portable and clean definition in R6RS, if it exists, or
>> 2. Any reasons why including a primitive bound-identifier? (in the
>> syntax-case library, say) would be a bad idea (presuming there is no
>> solution to 1).
> I do not know if this is really clearly portable, but to me it is not
> obviously importable either. Since this can be done at any point in general
> outside of the top-level with 'free-identifier=?' I don't see a real reason
> to put another predicate in there.
> (define-syntax bound-identifier?
> (lambda (x)
> (syntax-case x ()
> [(k y) (identifier? #'y)
> #`#,(not (free-identifier=? #'y
> (datum->syntax #'a (syntax->datum #'y))))])))
> I think the choice for #'a may be important, but if this form is defined at
> the top level and 'a' is undefined, this should work. I think it works
> regardless so long as this form is defined at the top level. This form will
> only find bound identifiers in lexical scopes, since everything is
> free-identifier=? when we reach the top level in this case. However, I think
> this should work pretty well.
> Aaron W. Hsu
> Of all tyrannies, a tyranny sincerely exercised for the good of its victims
> may be the most oppressive. -- C. S. Lewis
More information about the r6rs-discuss