On Mon, Jun 22, 2009 at 12:08 PM, Aaron W. Hsu<[email protected]> wrote:
> Ramana,
>
> On Sun, 21 Jun 2009 20:31:11 -0400, Ramana Kumar <[email protected]>
> wrote:
>
>> If you could create an identifier whose wrap was known to be empty
>> (i.e. had no substitutions), then your trick with free-identifier=?
>> would work for imports and top-level definitions as well as
>> lower-level (e.g. let) bindings. That's why I asked whether such a
>> guarantee of an empty wrap could be made for the results of
>> generate-temporaries.
>
> I don't know if this is possible, but using EVAL on a null environment would
> work, I think, to achieve a syntax which was not wrapped with any of the
> other bindings. However, I don't think this will work with the
> 'free-identifier=?' technique for determining whether something is bound or
> not.
I assume you mean something like this: (eval '#'foo (environment
'(only (rnrs) syntax))).
Notice that you still need "syntax" in the environment, so it's not a
completely empty environment. (I don't think you can create an
identifier with a completely empty wrap - unless generate-temporaries
is a way to do that.)

Now with this foo with an almost-empty wrap, I can define
bound-identifier? as follows (also see Derick's message for a more
complete version of this idea):
(import (rnrs) (rnrs eval))
(define bound-identifier?
  (let ((empty (eval '#'foo (environment '(only (rnrs) syntax)))))
    (lambda (id)
      (or (free-identifier=? id #'syntax)
        (not (free-identifier=? id (datum->syntax empty (syntax->datum
id))))))))

(display
  (list ; should be (#t #f #t #f #f #t)
    (bound-identifier? #'car)
    (bound-identifier? #'foo)
    (let ((x 3)) (bound-identifier? #'x))
    (let ((x 3)) (bound-identifier? #'y))
    (let ((x 3)) (bound-identifier? #'foo))
    (let ((x 3)) (bound-identifier? #'car))))

If the script above is portable it might be the answer to my original
question 1...

>
> The semantics of 'free-identifier=?' is to assume that there is a top-level
> environment in which all bindings are considered to be bound, and then to
> examine the two syntaxes given, and determine whether the two would
> reference the same location given that they existed as free identifiers in
> the scope wherein the call to 'free-identifier=?' occurs. If you are given
> one identifier at some scope, and then construct another identifier created
> as a top-level scoped variable with the same name or form as the other
> identifier, applying 'free-identifier=?' to these two syntaxes gives two
> possible results:
free-identifier=? doesn't (and can't) know anything about the
environment of its call site. It uses the lexical information in the
wraps of the its arguments.

>
> 1) If the original syntax is bound to a lexical variable, then the two
> variables must by definition reference different locations, and therefore,
> the call must return false.
>
> 2) If the original syntax is not bound to any lexical variable, then the
> semantics of 'free-identifier=?' requires that we assume that the identifier
> is bound at the top-level, and since the wraps on the two names are now the
> same, the call must return true.
>
> That is, it is because we have this top-level break point that we can catch
> bindings when they occur at any internal scope that is more narrow than the
> top-level. If we were to be given a syntax wrapped in a null environment, it
> would never be 'free-identifier=?' to anything, and both of the two cases
> above must return false, because it will never happen that the two
> identifiers reference the same location. At least, this is how it seems to
> me in my reading. I would appreciate any correction on my understanding of
> how this works.
>
> To answer your other question, about 'generate-temporaries', I also don't
> think that this will work. Reading the R6RS definition of
> 'generate-temporaries', I am inclined to think that there is no guarantee
> made about the wrapping, and thus, one can't guarantee how the wrapping
> occurs there. Also, what exactly is a "null" wrapping? How would it be
> meaningful with regards to 'free-identifier=?'?.
>
> Sincerely,
>
>        Aaron W. Hsu
>
> --
> Of all tyrannies, a tyranny sincerely exercised for the good of its victims
> may be the most oppressive. -- C. S. Lewis
>

_______________________________________________
r6rs-discuss mailing list
[email protected]
http://lists.r6rs.org/cgi-bin/mailman/listinfo/r6rs-discuss

Reply via email to