Horner's rule for polynomial evaluation: Difference between revisions

Content added Content deleted
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
m (→‎{{header|Raku}}: Fix link and comments: Perl 6 --> Raku)
Line 1,576: Line 1,576:
say horner( [ -19, 7, -4, 6 ], 3 );</lang>
say horner( [ -19, 7, -4, 6 ], 3 );</lang>


A recursive version would spare us the need for reversing the list of coefficients. However, special care must be taken in order to write it, because the way Perl 6 implements lists is not optimized for this kind of treatment. [[Lisp]]-style lists are, and fortunately it is possible to emulate them with [http://doc.perl6.org/type/Pair Pairs] and the reduction meta-operator:
A recursive version would spare us the need for reversing the list of coefficients. However, special care must be taken in order to write it, because the way Raku implements lists is not optimized for this kind of treatment. [[Lisp]]-style lists are, and fortunately it is possible to emulate them with [http://doc.raku.org/type/Pair Pairs] and the reduction meta-operator:


<lang perl6>multi horner(Numeric $c, $) { $c }
<lang perl6>multi horner(Numeric $c, $) { $c }