Simple stage that keeps slots as key-value pairs in built-in AA.
Simpliest of all - just a constant, stays the same, regardless of _stage_
Slot - a placeholder for value, that will be provided at a later _stage_
Lift a simple constant
Stage is equivalent to DI container (or rather DI is simple late-binding + basic form of staging) but the composition and execution of them is independent and encapsulated by Lift!T interface
Built with love based on the ideas in the paper:
Lightweight Modular Staging: A Pragmatic Approach to Runtime Code Generation and Compiled DSLs by Tiark Rompf and Martin Odersky.
The above paper and many other good ones by Scala team at EPFL are here http://infoscience.epfl.ch/record/150347/files/gpce63-rompf.pdf.
Synopsis
auto stage = new BasicStage(); int[] trace; // our primitive trace buffer auto v1 = stage.slot!double("var1").map(delegate double(double x) { trace ~= 1; return x; }); auto v2 = stage.slot!double("var2").map(delegate double(double x) { trace ~= 2; return x; }); stage["var1"] = lift(1.5); auto part = (v1 + v2).partial(stage); stage["var2"] = lift(-0.5); // first pass - both map functions called once assert(part.eval(stage) == 1.0); assert(trace == [1, 2]); // second pass - only v2 is evaluated assert(part.eval(stage) == 1.0); assert(trace == [1, 2, 2]);
Lightweight Modular Staging library for D langauge.
Popularization of dependency injection framework somehow shaded the bigger and more general technique - staging and staged computation.
This library ractifies that omission for the D language.