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