-
Notifications
You must be signed in to change notification settings - Fork 987
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
free-identifier=?
treats uninterned symbols as if interned for the fallback comparison
#902
Comments
This has not much to do with the semantics of Run the example in an R6RS program, and you'll see that it works. |
The current behavior does seem wrong. I've looked into this some, but not yet enough to propose a change. |
The current behaviour of
prints When run at the top-level, i.e. when running the program
we get The program
prints This is why I wrote above that Thus, if any behaviour is to be changed (I am not sure whether it should), it would be the behaviour of the interaction environment. |
The interaction environments (and other environments) use @dpk is using the procedure In fact, the program
prints |
Let me finally point out that this proposed use of gensyms leads to, at least, unintuitive macros: Please read (import (chezscheme))
(define-syntax put
(lambda (stx)
(syntax-case stx ()
[(k x)
(with-implicit (k secret-id)
#'(define secret-id x))])))
(define-syntax get
(lambda (stx)
(syntax-case stx ()
[(k)
(with-implicit (k secret-id)
#'secret-id)])))
(let ()
(put 42)
(pretty-print (get))) As expected, the program prints However, it is not transparent to syntactic abstraction. For whatever reason, the user might want to introduce a convenience macro, ultimately expanding to the first of the two macros above: (let-syntax
([my-put
(syntax-rules ()
[(_ x) (put x)])])
(my-put 42)
(pretty-print (get))) And this macro breaks. (Incidentally, this particular example wouldn't have broken if Another problem with the approach of "invisible identifiers" is that it breaks down when the user uses the (module env (pretty-print get))
(let ()
(put 42)
(import-only env)
(pretty-print (get))) Intuitively, it should work but doesn't. But even if it shouldn't work, the user has no way to repair it because the secret identifier is, well, secret and cannot be put into the module exports. Syntax parameters, on the other hand, do not have any of these problems, but their effect is more global (and, as with any form of dynamic binding, one has to program carefully). |
What you refer to as ‘broken’ is the intended behaviour of my use case. |
I understand that this can be the intended behaviour in some cases (i.e. when a put/get pair is independently introduced by two unrelated macro pairs). The intention of my example was to show that what can be the intended behaviour for some use cases can be quite unintuitive in other cases (and can lead to code where syntactic abstraction doesn't work anymore). Note that (let-syntax
([my-get
(syntax-rules ()
[(_) (get)])])
(put 42)
(pretty-print (my-get))) does not give an error, so whether the macro "breaks" or not depends on whether Maybe it is (or the example does not apply to your use case), but in any case, we should probably move this discussion somewhere else as it is not directly related to the reported issue. As far as the reported issue is concerned, it seems to me that it can be closed. According to the documentation, "uninterned symbols" (those produced by |
Although
datum->syntax
appears to preserve the uninternedness of identifiers’ symbolic names,free-identifier=?
ignores it:This is rather unintuitive. Symbols never compare by their textual name anywhere else, always by their location in the store. This goes against the raison d’être of the fallback case for
free-identifier=?
, which is that the two identifiers would have the same binding if defined at the top level. It also likely prevents or makes significantly trickier the use of uninterned symbols as a mechanism for communication between macro expansions, though I haven’t actually experimented with that yet. (This issue was discovered in the course of a discussion about potentially introducing uninterned symbols to R7RS large, where they would mostly be available for this purpose.)The text was updated successfully, but these errors were encountered: