Sujet : Re: Help with GA, and critique my Lisp (please ;-))
De : Nobody447095 (at) *nospam* here-nor-there.org (B. Pym)
Groupes : comp.lang.lisp comp.lang.schemeDate : 26. Sep 2024, 03:27:30
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vd2gqh$1c8r$1@dont-email.me>
User-Agent : XanaNews/1.18.1.6
Geoffrey Summerhayes wrote:
>
(defun evaluate-poly (p x)
(loop for coeff in p
for power from 0
sum (* coeff (expt x power)))
>
A little wasteful, but what the heck.
>
(defun evaluate-poly (p x)
(reduce #'(lambda (a c) (+ c (* x a)))
(reverse p) :initial-value 0))
It ought to be "(lambda", not "#'(lambda". However, disciples
of CL (COBOL-Like) always try to make their code as ugly and
as prolix as possible. He would have been even more pleased
if he could have written:
(#'reduce #'#'#'#'#'#'#'#'#'(lambda (a c) (#'+ c (#'* x a)))
Gauche Scheme:
(define (eval-poly p x)
(fold-right
(^(c a) (+ c (* x a)))
0 p))