3 ms·
> and I still don't understand why I've never seen it elsewhere. Because reflecting upon environments at run-time is a silly eval hack that defies compilation.
by kazinator 10y ago
> and I still don't understand why I've never seen it elsewhere.
Because reflecting upon environments at run-time is a silly eval hack that defies compilation.
An environment that is exposed to the code at run-time cannot be efficiently treated by the compiler.
Lisp compilers throw away lexical environments when the dust settles.
An environment isn't something that is there, but you are blocked from accessing it by the evil Lisp implementation that doesn't provide an API. It in fact isn't there, except when the code is being inefficiently interpreted.
- shakna 10y agoIt can be ineffecient to generate and pass environments around, but it doesn't have to be, nor does it have to be a hack. Compiling with continuations [0] gives you a very efficient output, and a lexical environment that is easily modified, and intuitive to exist. Combine that with Cheney on the MTA, and first class environments are no more costly than a lambda. It is also possible to compile the initial environment [1], which makes it simpler to JIT any functions later linked to the structure. I'm not sure why you think a compiler has to throw away the environment, its certainly not what MIT Scheme does, as environments are special forms that persist as you go down and up the stack. [2] [0] http://matt.might.net/articles/cps-conversion/ http://matt.might.net/articles/cps-conversion/ [1] https://github.com/gambit/gambit/commit/09284455ae7c7e8dff4a71b8a60e5315e04fbe61 https://github.com/gambit/gambit/commit/09284455ae7c7e8dff4a... [2] https://groups.csail.mit.edu/mac/ftpdir/scheme-7.4/doc-html/scheme_14.html https://groups.csail.mit.edu/mac/ftpdir/scheme-7.4/doc-html/...