• Re: merits of Lisp vs Python

    From B. Pym@Nobody447095@here-nor-there.org to comp.lang.lisp on Wed Jun 18 21:25:23 2025
    From Newsgroup: comp.lang.lisp

    Wade Humeniuk wrote:

    John Thingstad wrote:

    (defun + (array) (loop for number across array summing number))
    for a array.


    Really?

    CL-USER 1 > (reduce '+ #(1 2 3))
    6

    Gauche Scheme

    (use gauche.sequence)

    (fold + 0 #(1 2 3))
    ===>
    6
    --- Synchronet 3.21d-Linux NewsLink 1.2
  • From Kaz Kylheku@643-408-1753@kylheku.com to comp.lang.lisp on Thu Jun 19 03:06:49 2025
    From Newsgroup: comp.lang.lisp

    On 2025-06-18, B. Pym <Nobody447095@here-nor-there.org> wrote:
    Wade Humeniuk wrote:

    John Thingstad wrote:

    (defun + (array) (loop for number across array summing number))
    for a array.


    Really?

    CL-USER 1 > (reduce '+ #(1 2 3))
    6

    Gauche Scheme

    (use gauche.sequence)

    (fold + 0 #(1 2 3))

    Alas, that could have been

    (fold + #(1 2 3))

    if they had only copied the good idea: when the initial accumulator is
    not specified, infer it by calling the function without arguments.

    With functions like +, you usually want the reduce accumulator to be the identity element, and the function can give it to you: (+) -> 0.

    For the list appending monad, the empty list is the identity element,
    and that's what (append) returns, so it works for that too:

    (reduce #'append '((1) (2 3 4) (5))) -> (1 2 3 4 5)
    --
    TXR Programming Language: http://nongnu.org/txr
    Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
    Mastodon: @Kazinator@mstdn.ca
    --- Synchronet 3.21d-Linux NewsLink 1.2