Record Tutorial
Copy of 30.Record Update Selectors
Tuple and record elements may have a functional type.
The following example uses a collection
of named float functions to compute a table of
their values.
Source code:
apply(
functions,
[0.0, 0.5, 1.0, 1.5]
)
where{
functions = [
{ name:"Id "; fn:\x:x },
{ name:"Sinus "; fn:sin },
{ name:"Cosinus"; fn:cos },
{ name:"Square "; fn:\x:x*x }
];
apply( functions, values ) =
if functions->empty() then ''
else
functions->hd().name
+ applyFn( functions->hd().fn, values )
+ "\n"
+ apply( functions->tl(), values );
applyFn( fn, values ) =
if values->empty() then ''
else
" "
+ asString(0.0+fn( values->hd()+0.0 ))
+ applyFn( fn, values->tl() );
}
Result:
"Id 0.000000 0.500000 1.000000 1.500000
Sinus 0.000000 0.479426 0.841471 0.997495
Cosinus 1.000000 0.877583 0.540302 0.070737
Square 0.000000 0.250000 1.000000 2.250000
"
|