News for hackers. Stuff that matters.
Re:We're the core Urbit team, ask us anything about Urbit by kazinator on Friday June 17, 2016 @10:49PM (#11926783)
cyarvin: But more broadly, it's very difficult to invent a system like this if you need to commit to reusing the abstractions of 20th-century programming. A reused term comes with all kinds of assumptions. Sure, in some cases it's possible to retcon the system back into "normal" language, but a mismatch should be expected. A good example is the homoiconic state of Hoon/Nock. In basically all other languages, even including Lisp, the set of data available to an expression is not a first-class value in the language -- it's a "scope" or "environment" or some other secret mystery meat. In both Hoon and Nock it's a single, ordinary value -- the subject.

In mainstream Lisp dialects, that first class value exists: it is the lexical closure. You might not like the indirect "API" that it gives you to the environment (namely a function, which you have to program yourself to do what you want), but that's what it is. Your function can contain logic to inspect variables:

  ;; CL
  (let ((a 1) (b 2) (c 3))
    (lambda (which-var)
      (ecase which-var (a a) (b b) (c c))))
If we bind this to f, and (funcall f 'a) we get 1, and so on; we've given the mystery meat object a method for looking at some of the accessible values.

There may be some object representing an actual environment. That is very dialect specific. Common Lisp has macro-time environments, so a macro can manually expand a sub-macro in the correct scope.

In the TXR Lisp dialect, you can do this:

  1> (make-env)
  #<environment: b7653e3c>
  2> (env-vbind *1 'a 3)
  (a . 3)
  3> (env-vbind *1 'b 2)
  (b . 2)
  4> (eval '(+ a b))
  ** (expr-4:1) unbound variable a
  5> (eval '(+ a b) *1) ;; pass in the env
  5
In principle, any dialect could have this. I think it's just not considered that useful in the Lisp world. For one thing, compiled code may want to use an optimized representation of the environment. A compile function could take an env also, but that env would likely be copied and transformed into something else (that no longer shares bindings with the original env object).

Environments as first-class values are bit of an antithesis to the compiling of efficient lexical scopes. This is not out of ignorance; the Lisp world made that choice way back when for some good reasons. (Those reasons are neither forgotten, nor unquestioned).

There are no comments on this comment yet.