Re:The death of if/else cascades, a lightweight alternative
by DrJokepu on Sunday December 06, 2009 @12:59PM
(#979881)
Compilers are special because their input/output data is code and instructions. However the code of the compiler itself is clearly separated from the code the compiler emits. When the compiler uses the lookup table to look up the code to emit it really looks up data for output and not code to be executed (right away).
Re:The death of if/else cascades, a lightweight alternative
by jfoutz on Monday December 07, 2009 @12:55PM
(#981621)
Another cool trick is runtime rebinding.
Context sensitive actions come to mind. s means save when editing, or s means stop when running. This is also a common way to let users remap keys, or build their own menus.
Similarly, compilers often use this approach for instruction generation. The set of available machine instructions is stored as a table; if you move to a different architecture, you just replace the table with one appropriate to the new architecture.
This is not a new idea. SICP has a whole section on data-directed programming, and MapReduce and many other internal bits of Google infrastructure use this extensively.