This article is done in a literate programming style, attempting both to teach the basics of Lisp writing style and to describe the details of this static binding implementation.
In the TXR Lisp compiler load-time (what load-time-value is called: of course there is always a value, so why mention it) is used in the implementation of lambda hoisting.
E.g. if your compiler doesn't have lambda hoisting, you cna manually do it like this:
This works if the function doesn't make any references to the lexical environment of the surrounding function. Then the lambda gets instantiated once and becomes a "virtual literal" in the loaded code; calls to my-fun no longer have to construct a closure; they just pull it out of the static data, where it is in a kind of fixed register at a known position.
The compiler has to recognize cases when this can be done automatically and make it so.
2 comments
[ 0.91 ms ] story [ 8.8 ms ] threadE.g. if your compiler doesn't have lambda hoisting, you cna manually do it like this:
This works if the function doesn't make any references to the lexical environment of the surrounding function. Then the lambda gets instantiated once and becomes a "virtual literal" in the loaded code; calls to my-fun no longer have to construct a closure; they just pull it out of the static data, where it is in a kind of fixed register at a known position.The compiler has to recognize cases when this can be done automatically and make it so.