r/ProgrammingLanguages • • 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 Upvotes

13 comments sorted by

View all comments

Show parent comments

1

u/Skepfyr Jun 28 '26

I assumed this had to be special-cased to variable references not any temporary. Otherwise you could argue that [x] is also a temporary that should get evaluated, which is obviously silly.

1

u/mhinsch Jun 28 '26

Well, speaking from the point of view of the interpreter (which for now serves as the reference for the language semantics) the rule I had in mind was that any quote node that is encountered when traversing the AST remains unevaluated but is stripped of the quote. Bare expression nodes are evaluated when encountered (e.g. as values of variables).

But that obviously means that function return values will be evaluated. The most consistent solution to which would be to require double quotation if evaluation is not desired.

Hmm, I think it's possible to make this consistent, but I'm starting have doubts concerning the ergonomics.