[Solar-general] perl 6, el operador "*+*" y fibonacci
Diego Saravia
dsa en unsa.edu.ar
Jue Jul 22 06:44:49 CEST 2010
What does PL/Perl 6 look like? Here is a nice example of a PL/Perl6
function which calculates the sum of all Fibonacci numbers <= 100:
CREATE FUNCTION test_fibonacci_plperl6(integer) RETURNS int LANGUAGE
plperl6 AS $$
[+] (1, 1, *+* ... 100)
$$;
You will notice three spiffy new Perl 6 operators in there, the
summation operator [+], the new range operator ... (which used to be
.. in Perl 5), and the *+* operator. What exactly is the *+* operator?
pmichaud++ jokingly referred to it as the "cheerleading plus", but it
is actually just a plain old infix "+" operator, sandwiched by two "*"
(a.k.a Whatever) operands. It basically takes the previous two
elements in a list, sums them together and returns the sum, which is
exactly how the Fibonacci sequence is defined.
--
Diego Saravia
Diego.Saravia en gmail.com
NO FUNCIONA->dsa en unsa.edu.ar
Más información sobre la lista de distribución Solar-general