Re: Help with GA, and critique my Lisp (please ;-))

Liste des GroupesRevenir à cl scheme 
Sujet : Re: Help with GA, and critique my Lisp (please ;-))
De : 643-408-1753 (at) *nospam* kylheku.com (Kaz Kylheku)
Groupes : comp.lang.lisp comp.lang.scheme
Date : 26. Sep 2024, 04:53:27
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <20240925205127.543@kylheku.com>
References : 1
User-Agent : slrn/pre1.0.4-9 (Linux)
On 2024-09-26, B. Pym <Nobody447095@here-nor-there.org> wrote:
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))

TXR Lisp:

1> (poly 0.5 '(2 3 4))
6.0
2> (rpoly 0.5 '(2 3 4))
4.5


--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca

Date Sujet#  Auteur
26 Sep 24 * Re: Help with GA, and critique my Lisp (please ;-))2B. Pym
26 Sep 24 `- Re: Help with GA, and critique my Lisp (please ;-))1Kaz Kylheku

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal