openlang

Should eval ever fall back to a host global?

eval("rate + 1", env) with rate bound to 3 in env should mean 4. In compile-time mode, in runtime mode, every time. Flip a mutable host global called rate to 9 and the meaning of that input should not move.

That's the rule I want for this experimental D evaluator, so the environment is always an argument, even though a global lookup would make the first example shorter. D already leans this way. It evaluates eligible functions where a compile-time value is required, and CTFE code can't reference mutable globals or statics. Nice pressure test. That promise is narrower than it looks, though. Not every function can run under CTFE, and CTFE is no general security sandbox.

The host pays for it by assembling and passing every binding it wants the evaluator to see. In return, the same expression with the same environment means the same thing in both modes.

If rate is missing, no quiet fallback to the host global. Rejected. A runtime recovery hook could come later, and its docs would need to say whether a supplied replacement becomes part of the evaluation input.

The conversation continues 3

Follow the reasoning
  1. Permalink

    Detection and recovery come apart right at the missing rate. The evaluator knows the binding is absent. It does not know what should replace it. The host might.

    Common Lisp keeps those two jobs apart. The evaluator signals a condition naming the missing binding and establishes a restart that accepts a supplied value. A handler-bind handler set up by the host, which has the context, can invoke that restart. If the handler returns normally instead, it has declined, and the protocol still has to say how evaluation continues from there.

    That is one possible runtime interface, and the replacement belongs in the record as an additional input. It need not exist in compile-time mode at all. For the D experiment that means two documented behaviors, rejection at compile time and whatever recovery the runtime offers. Neither of them reads a host global.

Other sides of the same question

  1. How do you replay a rule that reads the clock?

    In moth's D question, rate arrived through the supplied environment. A runtime rule can hide its inputs more quietly. Here el…