Skip to content

Commit

Permalink
Minor edits to improve the documentation of reduce.
Browse files Browse the repository at this point in the history
  • Loading branch information
okamsn committed Nov 10, 2023
1 parent 764281f commit 5af0db0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
12 changes: 7 additions & 5 deletions doc/loopy-doc.org
Original file line number Diff line number Diff line change
Expand Up @@ -2526,11 +2526,13 @@ The commands are described in more detail below.

This command also has the alias =reducing=.

When =VAR= does not have an explicit starting value (given with the special
macro argument =with=), the first accumulated value is =EXPR=. The first
accumulated value is not the result of passing =VAR= and =EXPR= to =FUNC=.
Using the =with= special macro argument is similar to using ~cl-reduce~'s
=:initial-value= keyword argument.
Note that the first accumulated value depends on the initial value of =VAR=.
By default, the first accumulated value is the value of =EXPR=, not a result
of calling =FUNC=. However, if =VAR= has an initial value given by the =with=
special macro argument, then the first accumulated value is the result of
~(funcall FUNC VAR EXPR)~, as also done in the subsequent steps of the loop.
This use of =with= is similar to the =:initial-value= keyword argument used by
~cl-reduce~.

#+begin_src emacs-lisp
;; => 6
Expand Down
10 changes: 9 additions & 1 deletion loopy-commands.el
Original file line number Diff line number Diff line change
Expand Up @@ -2645,7 +2645,15 @@ This function is used by `loopy--expand-optimized-accum'."
(loopy--defaccumulation reduce
"Parse the `reduce' command as (reduce VAR VAL FUNC &key init).
With INIT, initialize VAR to INIT. Otherwise, VAR starts as nil."
With INIT, initialize VAR to INIT. Otherwise, VAR starts as nil.
By default, the first accumulated value is the value of VAL,
not a result of calling FUNC. However, if VAR has an initial
value given by the =with= special macro argument, then the first
accumulated value is the result of `(funcall FUNC VAR VAL)', as
also done in the subsequent steps of the loop. This use of
`with' is similar to the `:initial-value' keyword argument used
by `cl-reduce'."
:num-args 3
:keywords (init)
:category generic
Expand Down

0 comments on commit 5af0db0

Please sign in to comment.