First-class functions/Use numbers analogously: Difference between revisions
Content deleted Content added
m →{{header|Scala}}: fix missing tag |
Use 'curry', compare to "First class functions" |
||
Line 386:
=={{header|PicoLisp}}==
<lang PicoLisp>(load "@lib/math.l")
(de multiplier (N1 N2)
(
(*/ N1 N2 X `(* 1.0 1.0)) ) )
(let (X 2.0 Xi 0.5 Y 4.0 Yi 0.25 Z (+ X Y) Zi (*/ 1.0 1.0 Z))
Line 402:
0.500000
0.500001</pre>
This follows the same structure as [[First-class functions#PicoLisp]], just
that the function 'multiplier' above accepts two numbers, while 'compose'
below accepts two functions:
<lang PicoLisp>(load "@lib/math.l")
(de compose (F G)
(curry (F G) (X)
(F (G X)) ) )
(de cube (X)
(pow X 3.0) )
(de cubeRoot (X)
(pow X 0.3333333) )
(mapc
'((Fun Inv)
(prinl (format ((compose Inv Fun) 0.5) *Scl)) )
'(sin cos cube)
'(asin acos cubeRoot) )</lang>
With a similar output:
<pre>0.500001
0.499999
0.500000</pre>
=={{header|Python}}==
|