Anonymous user
Apply a callback to an array: Difference between revisions
→{{header|Tcl}}: + functional: map
(→{{header|C}}: + AWK) |
(→{{header|Tcl}}: + functional: map) |
||
Line 1,012:
foreach name [array names dat] { myfunc $dat($name) }
</lang>
More functional, with a simple map function:
<lang Tcl>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</lang>
=={{header|Toka}}==
|