3 ms·
Many of the nice features mentioned are R6RS things, or extensions of that line. However, some R5RS schemes have extensions to support this behaviour. I'll use
by dleslie 10y ago
Many of the nice features mentioned are R6RS things, or extensions of that line. However, some R5RS schemes have extensions to support this behaviour. I'll use my favourite, Chicken, as an example:
* Applicative Syntax for Data Structures[0]
* First-class Environments[1]
0: http://wiki.call-cc.org/eggref/4/callable-data-structures http://wiki.call-cc.org/eggref/4/callable-data-structures
1: http://wiki.call-cc.org/eggref/4/environments http://wiki.call-cc.org/eggref/4/environments
- kazinator 10y agoI included some first-class environment manipulation in TXR Lisp. It's an obvious feature. They are already first-class in the internals; you just have to expose the API: The API is very small, though: http://www.nongnu.org/txr/txr-manpage.html#N-01144687 http://www.nongnu.org/txr/txr-manpage.html#N-01144687 Just make-env, env-vbind and env-fbind. The intent is to be able to prepare an object which can be passed as the optional environment parameter to eval and its ilk. First class environments of this type are not incredibly useful; they encourage the developer to create a more sophisticated eval hairball. (First class environments in macro-expansion are incredibly useful, on the other hand; but that is at code walking time, not run-time!) Note that no provision is made to allow a form access the current environment as a first class object. That is deliberate; by doing that, you turn the language into NewLisp or Tcl, slamming the door on future efficient compilation. Code should be written based on the assumption that there is no current environment, as an object. The compiler decides how the abstract environment maps to the machine code, and it's usually not via some object that neatly associates symbols with value places. It would literally be a five minute hack to provide a special operator form like `(my-env)` that just yields the environment object when evaluated, but the damage these five minutes would inflict on the language would be inestimable.
- abecedarius 10y agoAre you assuming mutable environments? If a first-class immutable environment is so costly, it's not clear to me.
- qwertyuiop924 10y agoAgreed, but some of those features are quite useful. Allowing for tcl/lua-style "upvars" means that a whole class of macros no longer have to be written. I often wish it were more possible to extend the environment of an existing closure, as this would allow for real dynamic variables (as opposed to the hack that Scheme has now, which is actually terrible).