I have been comparing ways of expressing an IMGUI API in Odin and Jai.
Odin’s @(deferred_none=...) already gives me most of the lifetime behaviour I want, and I use it like this:
// I write it this way to make it clear which call the scope belongs to.
{lay.element("toolbar")
lay.style(toolbar_style)
lay.text("Toolbar")
}
Those braces are only a surrounding scope. The children do not syntactically belong to the element call. This makes it easier to accidentally attach elements to the wrong parent, and makes components harder to compose.
In Jai, I found this form surprisingly useful:
element("toolbar", #code {
style(toolbar_style);
if hovered() {
style(hovered_style);
}
text("Toolbar");
});
It looks like a callback, but it does not create a runtime callback or closure. The code block is inserted at the call site and can use the caller’s locals. The implementation can effectively expand to:
open_element(label);
defer close_element();
#insert body;
This is useful for IMGUI systems because the element already exists while its body executes. It can inspect its own hover, focus, or interaction state and then style itself, while its children remain visually nested under the element call.
I am not suggesting that Odin adopt Jai’s general metaprogramming model, and the syntax above is illustrative only. The capability I am interested in is a procedure like construct accepting a statement block that is expanded once in the caller’s lexical scope, without creating a runtime callback or capture object.
I think the same shape could be useful for other scoped operations, such as locks, or transactions, although UI is the use case I have actually implemented.
Would something in this direction fit Odin’s design, or is there an existing Odin-shaped way to express it?