|Page 258 of 800||Search internet|
As an example of a non-trivial renderer, consider the txt construct defined in the following. Rendering of txt ( t ) causes t to be evaluated and the value to be included in the rendering. The value of t is supposed to be a string.
As an example of use,
txt ( lgc-itoa ( quote x + y end quote idx ) )
is rendered as the index of the plus construct expressed as the decimal number 588. That may be useful when writing pages like the present one.
The definition of the txt construct reads:
tex use define txt ( t ) as render-txt end define
The definition states that rendering of the txt construct is done by render-txt. The definition of render-txt reads:
eager define render-txt as map ( \ x . render-txt1 ( x ) ) end define
The definition says that rendering is actually done by render-txt1. The render-txt construct is just a maptagged closure of render-txt1. Now comes the meat of the definition:
eager define render-txt1 ( x ) as newline let a :: s :: c :: T = x in newline let f :: C :: V = s in newline let << t >> = a in newline let t = macro3 ( t , macrostate0 , c ) in newline let t = eval ( t , true , c ) untag in newline t :: C end define
The render-txt1 function decomposes x into a list of subterms of txt ( t ), a rendering state s, a cache c, and a list T of subterms of render-txt. The list T is empty because render-txt has no subterms.
Then render-txt1 decomposes the state s into renderer f, accumulating state C, and pass down state V.
Then render-txt1 decomposes the list a into the parameters of txt ( t ). There only is one parameter, namely t.
Then render-txt1 macro expands and evaluates the term t. Rendering is done on basis of the unexpanded body, so it is a good idea to macro expand before evaluation. Otherwise, lots of constructs will not evaluate as they used to do.
Finally, render-txt1 returns the pair t :: C. The render-txt1 construct has noting to add to the accumulating state C, so it just returns it unmodified.
|Page 258 of 800||Search logiweb.eu|