RosettaCodeData/Task/Apply-a-callback-to-an-array/Tcl/apply-a-callback-to-an-array-3.tcl

10 lines
159 B
Tcl
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
proc map {f list} {
set res {}
foreach e $list {lappend res [$f $e]}
return $res
}
proc square x {expr {$x*$x}}
% map square {1 2 3 4 5}
1 4 9 16 25