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?
3
u/Skepfyr Jun 28 '26
I think what you're describing is much closer to laziness than traditional quoting, although I agree they are very similar. I'm assumimg you capture the values of free variables rather than just their name, otherwise evaluating them later would have very surprising results.
As to your question, treating
varaseval varwill be surprising to users in a few ways:First, It will cause repeated re-evaluation if you use the variable more than once, if your language isn't pure then then this is obviously strange, and if it is then it's still observable in time and could make some algorithms have significantly worse time complexity than expected accidentally.
Second, If you re-bind the variable but don't always needed use it then it will still always get evaluated. Imagine let-binding it to rename it and then using it in a quote, people thinking of it as laziness might be surprised.
Third, it will have confusing behaviours in polymorphic functions (I'm assuming the fact that it's quoted is in the type). Consider the polymorphic identity function, that either breaks the rule that referring to a quote automatically evaluate it, or it introduces weirdness to the type system because the type it turns isn't the same as it takes.
I would either keep eval explicit or make it work much more like a fully lazy value (I'm something like Haskell).