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

    From B. Pym@21:1/5 to Geoffrey Summerhayes on Thu Sep 26 02:27:30 2024
    XPost: comp.lang.scheme

    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))

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kaz Kylheku@21:1/5 to B. Pym on Thu Sep 26 03:53:27 2024
    XPost: comp.lang.scheme

    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:

    (poly 0.5 '(2 3 4))
    6.0
    (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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)