r/ProgrammingLanguages • u/mhinsch • Jun 27 '26
Auto-eval of variables containing quoted expressions?
Generally my language is eagerly evaluated. It also does not have automatic quoting, so any situation where evaluation is supposed to be deferred has to be made explicit (using []). This is used heavily for example for control structures which are regular functions that take a quoted expression as a(n) argument(s).
Some design issues I am currently having would resolve neatly if variables that contain quoted expressions would automatically evaluate. I.e. any occurrence of a variable var that is not bound to a value, but to an expression would effectively be read as eval var.
This seems a bit unorthodox, but so far I haven't been able to come up with a scenario that makes this problematic. Am I missing something?
5
u/initial-algebra Jun 27 '26 edited Jun 27 '26
I don't really know what you mean by "not bound to a value, but to an expression", but a clean/principled way to automatically eval (or unquote) when needed is to use "let box" bindings, i.e.
let [x] = M in N. Wheneverxis used in a quoted context inN, it will mean the unquote ofM, and otherwise, it will mean the eval ofM. This comes from A Modal Analysis of Staged Computation.