A love letter to s7 Scheme
carloscarrasco.com
carloscarrasco.com
For the more knowledgeable, is (symbol-access) a complete general purpose primitive for reactive programming, like (delay) and (force) are for laziness?
> For the more knowledgeable, is (symbol-access) a complete general purpose primitive for reactive programming, like (delay) and (force) are for laziness?
As far as I know, yes, but careful about mutual references: if updating x when y changes triggers another update of y from x, you might never terminate.
* Applicative Syntax for Data Structures[0]
* First-class Environments[1]
0: http://wiki.call-cc.org/eggref/4/callable-data-structures
The API is very small, though:
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.
Unfortunately, I can't get the latest version of CM to compile, and CM has been moving towards a GUI version, and away from teh command line, which I found kind of sad.
Still, CM is my preferred algorithmic composition environment, by far. It's a shame it's not better known.
However, it does make Scheme uniquely suitable for an embedded language, or turning Scheme into a host language.
This [0] sort of demonstrates the magic that first class environments add, and how they make re-writing a language, whilst its running, a breeze.
It gives you safety in eval, and means that the kind of methods that other languages need to use to create, say a Flask-like API, are just plain overkill.
[0] http://www.cs.rpi.edu/academics/courses/fall00/ai/scheme/ref...
Checkout: http://lambda-the-ultimate.org/node/3861
(let ((a +)) (null-environment))
Edit: I do really want to know if there is a simple answer. Being able to embed Luajit for some things like this would be awesome.
local env = {}
env['args'] = {...}
setfenv(f, env)
return f()Absolutely doable though.
env['f'] = myfunc
and the function will be available as f within the environment.https://cran.r-project.org/doc/manuals/r-release/R-lang.html...
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.
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/
[1] https://github.com/gambit/gambit/commit/09284455ae7c7e8dff4a...
[2] https://groups.csail.mit.edu/mac/ftpdir/scheme-7.4/doc-html/...
Also, first-class environments are amazing, and I wish my scheme-of-choice (CHICKEN) had them: It used to, but the code doesn't work with the new compiler, and the long-promised replacement hasn't been written yet.
Maybe I should just dive in and write it myself...
[1] https://en.wikipedia.org/wiki/Game_Oriented_Assembly_Lisp