Sujet : Re: merits of Lisp vs Python
De : 643-408-1753 (at) *nospam* kylheku.com (Kaz Kylheku)
Groupes : comp.lang.lispDate : 19. Jun 2025, 04:06:49
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <20250618200022.619@kylheku.com>
References : 1
User-Agent : slrn/pre1.0.4-9 (Linux)
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/txrCygnal: Cygwin Native Application Library: http://kylheku.com/cygnalMastodon: @Kazinator@mstdn.ca