<< The result of f applied to x is : $(f x). >>
<< Hello $(user.name) ! >>
There is also support for conditional sections
$?(cond)...?() or
$?(cond)...?(else)...?():
<< If you are me $?( user.id = me ) (and you are, actually) $(),
you can click here ... >>
<< $?( delta last_visit today > 10 ) Haven't seen you for a while !
$?(else) Oh, you again ... what do you want !? $() >>
And for iterations:
<< $[map_list players -> (name,score)]
<br> Player $(name) has score $(score).
$[]
>>
Section to be written, see the interface ../text.mli
3. The <:here<..>> quotation
HereDoc defines a Camlp4 quotation called here
and makes it the default one, so that you can just use
double brackets as in the introduction. The type of the
expression is Fragment.t (which may be string
but not necessarily).
<< Hello $( <<world>> ) ! >>The special form $() produce an empty fragment. This can be useful to "escape" sequences that would be recognized by HereDoc:
<< This is not an expression: $$()(). >>The $() produce the empty string, so the result is : This is not an expression: $().
$[expr -> pat1 -> .. -> patn] body $[]This will produce a fragment equivalent to:
expr (fun pat1 .. patn -> <<body>> )That is: expr is a functional, which is feed by the abstraction of body w.r.t. the patterns p1,...,pn. If n=0, it is just the application of expr to body. This can be useful to post-process a fragment:
$[rot13] This is a secret. $[](the function rot13: Fragment.t -> Fragment.t must be in the scope of the quotation where it appears) The other main application is the iteration over a list, for instance:
$[map_list l -> (x,y,_)] x=$(x); y=$(y) $[](where map_list can be defined by let map_list l f = Fragment.list (List.map f l) actually, it is already defined by the functor Tools). You can iterate over an array and use the index:
$[map_array a -> i -> name] $(name) is number $(int i). $[](with let map_array a f = Array.iteri f a and int: int -> Fragment.t is defined in Tools).
${format -> arg1 -> .. -> argn}
will produce a fragment equivalent to:
Printf.sprintf format arg1 .. argnFor instance:
Position: ${"(%03i,%03i,%03i)" -> x -> y -> z}
<< Special html chars: $(<:html< <, >, &, " >>) >>
The program used to produce this document rely heavily
on this quotation expander.
Actually, not for the moment ... It is an old version which is described on this page
up