Apply a callback to an array: Difference between revisions
Content added Content deleted
(Added Odin variant) |
No edit summary |
||
Line 1,653: | Line 1,653: | ||
{{Out}} |
{{Out}} |
||
<pre>array (1,10) [(1,1),(2,4),(3,9),(4,16),(5,25),(6,36),(7,49),(8,64),(9,81),(10,100)]</pre> |
<pre>array (1,10) [(1,1),(2,4),(3,9),(4,16),(5,25),(6,36),(7,49),(8,64),(9,81),(10,100)]</pre> |
||
=={{header|Guish}}== |
|||
{{works with|guish|2.1.5}} |
|||
<syntaxhighlight lang="guish"> |
|||
# applies add2 (adds 2) to each element |
|||
map = { |
|||
r = |
|||
args = [take(1, nargs(), @*)] |
|||
for x @args { |
|||
r = [@r, call(@1, @x)] |
|||
} |
|||
return @r |
|||
} |
|||
add2 = { |
|||
return add(@1, 2) |
|||
} |
|||
dump map(add2, 1, 2, 3, 4, 5, 6, 7) |
|||
</syntaxhighlight> |
|||
=={{header|Icon}} and {{header|Unicon}}== |
=={{header|Icon}} and {{header|Unicon}}== |