Magic function: Difference between revisions

Jump to navigation Jump to search
212 bytes added ,  14:52, 12 May 2020
no edit summary
mNo edit summary
No edit summary
Line 1: Line 1:
In APL implementation, '''magic functions''' are a technique that allows parts of an interpreter written in a language such as [[wikipedia:C (programming language)|C]] to be implemented in APL. Much like APL code stored in an APL string is evaluated during the execution of the [[Execute]] primitive, a magic function evaluates APL code stored in a C (or other implementation language) string while executing a primitive or derived function. Magic functions can allow APL implementers to work more quickly by using a higher-level language, and can even improve [[performance]] as APL allows the programmer to more easily access fast primitive implementations.<ref>[[Roger Hui]]. [http://www.dyalog.com/blog/2015/06/in-praise-of-magic-functions-part-one/ "In Praise of Magic Functions: Part I"]. [[Dyalog Ltd.|Dyalog]] blog. 2015-06-22.</ref>
In APL implementation, '''magic functions''' are a technique that allows parts of an interpreter written in a language such as [[wikipedia:C (programming language)|C]] to be implemented in APL. Much like APL code stored in an APL string is evaluated during the execution of the [[Execute]] primitive, a magic function evaluates APL code stored in a C (or other implementation language) string while executing a primitive or derived function. Magic functions can allow APL implementers to work more quickly by using a higher-level language, and can even improve [[performance]] as APL allows the programmer to more easily access fast primitive implementations.<ref>[[Roger Hui]]. [http://www.dyalog.com/blog/2015/06/in-praise-of-magic-functions-part-one/ "In Praise of Magic Functions: Part I"]. [[Dyalog Ltd.|Dyalog]] blog. 2015-06-22.</ref> Often they are used for testing new functionality or implementation techniques, as they can be easily changed during prototyping, and translated back to the implementation language after the code has stabilized.


Magic functions are not the only way to implement parts of an interpreter in APL: while a magic function is written as part of the interpreter's source code and called during execution, it may also be possible to define parts of the interpreter using external APL code executed at startup. Functionality like [[user command]]s is often written in APL in this way, and [[ngn/apl]] even uses this technique to implement primitives, as it allows primitives to be freely reassigned.
Magic functions are not the only way to implement parts of an interpreter in APL: while a magic function is written as part of the interpreter's source code and called during execution, it may also be possible to define parts of the interpreter using external APL code executed at startup. Functionality like [[user command]]s is often written in APL in this way, and [[ngn/apl]] even uses this technique to implement primitives, as it allows primitives to be freely reassigned.

Navigation menu