Horner's rule for polynomial evaluation: Difference between revisions

m
→‎{{header|Raku}}: Fix link and comments: Perl 6 --> Raku
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
m (→‎{{header|Raku}}: Fix link and comments: Perl 6 --> Raku)
Line 1,576:
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 6Raku 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.perl6raku.org/type/Pair Pairs] and the reduction meta-operator:
 
<lang perl6>multi horner(Numeric $c, $) { $c }
2,392

edits