Apply a callback to an array: Difference between revisions
Content added Content deleted
m (moved Apply a callback to an Array to Apply a callback to an array) |
No edit summary |
||
Line 378: | Line 378: | ||
} |
} |
||
println(map(square, array))</lang> |
println(map(square, array))</lang> |
||
=={{header|efene}}== |
|||
<lang efene>square = fn (N) { |
|||
N * N |
|||
} |
|||
# list comprehension |
|||
squares1 = fn (Numbers) { |
|||
[square(N) for N in Numbers] |
|||
} |
|||
# functional form |
|||
squares2a = fn (Numbers) { |
|||
lists.map(fn square/1 Numbers) |
|||
} |
|||
# functional form with lambda |
|||
squares2b = fn (Numbers) { |
|||
lists.map(fn (N) { N * N } Numbers) |
|||
} |
|||
# no need for a function |
|||
squares3 = fn (Numbers) { |
|||
[N * N for N in Numbers] |
|||
} |
|||
run = fn () { |
|||
Numbers = [1 3 5 7] |
|||
io.format("squares1 : ~p~n" [squares1(Numbers)]) |
|||
io.format("squares2a: ~p~n" [squares2a(Numbers)]) |
|||
io.format("squares2b: ~p~n" [squares2b(Numbers)]) |
|||
io.format("squares3 : ~p~n" [squares3(Numbers)]) |
|||
} |
|||
</lang> |
|||
=={{header|Factor}}== |
=={{header|Factor}}== |