On Thu, May 7, 2026, at 5:52 AM, Rowan Tommins [IMSoP] wrote:

> For something like "run this in a transaction", the closure is really 
> acting like a poor man's "continuation": it creates two new stack 
> frames (transaction wrapper, callback) when what you really want is to 
> *interleave* the boilerplate and the case-specific code.
>
> In that sense, hygienic macros are probably the "ideal" solution - 
> everything is expanded inline into a single scope, and there's no 
> Closure object which can be misused.
>
> Context Managers could in fact be implemented as such a macro, and as I 
> understand it, the implementation is basically doing that internally by 
> manipulating ASTs.

Correct.  Absent a macro system like Rust, it's just a one-off compiler "macro" 
that turns into try-catch-finally.

> I wonder if there's any "minimal" macro system which would allow this 
> kind of inline boilerplate expansion, without needing to design an 
> entire meta-language?

The PFA implementation does generate new opcodes at runtime and cache them.  So 
such things are possible.  Wise to generalize or not is an entirely separate 
question, though. :-)

--Larry Garfield

Reply via email to