You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Guess we need to write once as a macro. I'm not currently clever enough to realize whether we have the primitives available to express once as a macro in 007, or whether once itself needs to be such a primitive.
I think it can be done in pure 007. Funnily enough, we'll need another hidden COMPILING:: variable to express it:
@parsed(/ "once" >> <G.block> /)
macro term:<once>(block) {
my initialized = new Symbol("initialized");
return quasi {
my COMPILING::{{{initialized}}};
if !COMPILING::{{{initialized}}} {
{{{Q::Block @ block}}}
COMPILING::{{{initialized}}} = True;
}
};
}
The text was updated successfully, but these errors were encountered:
Rust has a "once cell" crate. Food for inspiration.
All of a sudden I'm also reminded of Josh Bloch's insistance that the singleton pattern should be implemented using enums. This has something to do with the built-in guarantees provided by the Java Virtual Machine itself during initialization.
From #313 (comment):
I think it can be done in pure 007. Funnily enough, we'll need another hidden
COMPILING::
variable to express it:The text was updated successfully, but these errors were encountered: