Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
17
Task/First-class-functions/Tcl/first-class-functions.tcl
Normal file
17
Task/First-class-functions/Tcl/first-class-functions.tcl
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
% namespace path tcl::mathfunc ;# to import functions like abs() etc.
|
||||
% proc cube x {expr {$x**3}}
|
||||
% proc croot x {expr {$x**(1/3.)}}
|
||||
% proc compose {f g} {list apply {{f g x} {{*}$f [{*}$g $x]}} $f $g}
|
||||
|
||||
% compose abs cube ;# returns a partial command, without argument
|
||||
apply {{f g x} {{*}$f [{*}$g $x]}} abs cube
|
||||
|
||||
% {*}[compose abs cube] -3 ;# applies the partial command to argument -3
|
||||
27
|
||||
|
||||
% set forward [compose [compose sin cos] cube] ;# omitting to print result
|
||||
% set backward [compose croot [compose acos asin]]
|
||||
% {*}$forward 0.5
|
||||
0.8372297964617733
|
||||
% {*}$backward [{*}$forward 0.5]
|
||||
0.5000000000000017
|
||||
Loading…
Add table
Add a link
Reference in a new issue