-
Notifications
You must be signed in to change notification settings - Fork 26
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
Closure variable not correctly exported to environment #83
Comments
Ah yes, the "split closure" problem. This is actually explicitly mentioned in the
Here's a thread in the old mailing list about it: http://wryun.github.io/es-shell/mail-archive/msg00799.html This problem was fixed in XS, but that codebase is too C++ for me to deeply understand how it works internally: TieDyedDevil/XS@bf8133b As far as I've seen (till now!), every proposed or implemented fix to this has involved some kind of "tagging" mechanism, so that you'd have something like
This tag, here shown something like how XS does it, indicates to the shell that these aren't just two Your idea of creating another extra variable to point to is interesting. It seems like it might be essentially equivalent to the tag-based method, but it could be simpler. You'll have to work with the fact that you might have a couple shared I think that ideally, whatever machinery is used for this would be also used to fix #4 at the same time, because both seem to come down to the same problem, which is that the existing closure externalization isn't powerful enough to represent the fully general cyclic graph structure of lexical bindings. As I have daydreamed it with a tag based method, you'd have something like
and between the new tags and the As an aside: I strongly believe that
is both the correct and most useful behavior. It's correct because the environment, being "process-global" state, isn't actually part of any lexical context inside the process. It's useful because I like to define named parameters to functions like |
I was curious and looked into things a little bit, and there's some additional hashing and stuff happening for some reason. The key is the contents of the Based on the commit log of XS and a bit of time looking at the code, the ID tags for the bound variables do seem like they would solve this particular issue.
Alas, #4 is a slightly different problem, though i understand why you might think that. |
Right, maybe I didn't properly communicate what I meant. There are two specific problems: printing cyclic references doesn't work (#4), and printing shared bindings doesn't work (this issue). My claim is that these are both rooted in a third, more general issue that the existing syntax to represent closures can't actually represent the full structure of lexical bindings. My personal preference would be to solve that general problem by finding some syntax to encode the structure of any set of bindings in a |
leads to this in the environment:
In the current shell, the y and z functions refer to the same
x
, but in a subshell they refer to distinct variables (as one would anticipate from the above environment).This behaviour is sort of hinted at in the man page:
But this seems to elide important details. From the perspective of the user, they can be be exported as part of a closure, but they're not correctly exported in this instance.
To fix this, presumably one would need to export necessary lexically bound variables in the environment and redefine how %closure works to be able to refer to these variables. Alternatively, it may be possible to export the entire 'let' construct and not export the functions separately, though this invites the possibility of an inconsistent environment (i.e. a function defined both in a let and independently, or indeed in separate lets).
The text was updated successfully, but these errors were encountered: