3 ms·
Here it is in Perl6: [+] ^6 Actually cheated slightly because ^6 creates list from 0..5 :) So correct match would be... [+] 1..5 Here's how you would d
by draegtun 13y ago
Here it is in Perl6:
[+] ^6
Actually cheated slightly because ^6 creates list from 0..5 :)
So correct match would be...
[+] 1..5
Here's how you would do it in Io:
list(1, 2, 3, 4, 5) reduce(+)
In Rebol there isn't a functional fold/reduce built in. So one way to do the one-liner would be:
x: [1 2 3 4 5] forskip x 2 [insert x '+] x: do next x
Above changes x to 15. Alternatively approach which doesn't clobber x:
x: [1 2 3 4 5] y: [] forall x [repend y [x/1 '+]] take/last y do y
I'm sure someone with more Rebol chops can see other (better!) ways of doing this :)