Version 1 of Map in functional programming

Updated 2004-10-29 07:56:14

map is function mapping, a classic primitive in functional programming - apply a function to all elements of a list, and return the resulting list:

 proc map {fun list} {
    set res {}
    foreach element $list {lappend res [$fun $element]}
    set res
 } ;# RS

 proc addTax x {expr {$x*1.16}}   

 % map addTax {1 10 5 2 1.95}
 1.16 11.6 5.8 2.32 2.262

Category Algorithm