Catamorphism: Difference between revisions

m (→‎{{header|V (Vlang)}}: "vfn" was changed to "fn" in the first line of code.)
Line 2,551:
return cat
</syntaxhighlight>
=={{header|RPL}}==
≪ → array op
≪ array 1 GET 2
WHILE DUP array SIZE ≤ REPEAT
array OVER GET ROT SWAP op EVAL
SWAP 1 +
END DROP
≫ ≫ 'REDUCE' STO
[ 1 2 3 4 5 6 7 8 9 10 ] ≪ + ≫ REDUCE
[ 1 2 3 4 5 6 7 8 9 10 ] ≪ - ≫ REDUCE
[ 1 2 3 4 5 6 7 8 9 10 ] ≪ * ≫ REDUCE
[ 1 2 3 4 5 6 7 8 9 10 ] ≪ MAX ≫ REDUCE
[ 1 2 3 4 5 6 7 8 9 10 ] ≪ SQ + ≫ REDUCE
{{out}}
<pre>
5: 55
4: -53
3: 3628800
2: 10
1: 385
</pre>
=={{header|Ruby}}==
The method inject (and it's alias reduce) can be used in several ways; the simplest is to give a methodname as argument:
Line 2,570 ⟶ 2,592:
# etc
</syntaxhighlight>
 
=={{header|Run BASIC}}==
<syntaxhighlight lang="runbasic">for i = 1 to 10 :n(i) = i:next i
1,150

edits