|
|
|
|
@ -216,122 +216,211 @@ This is the anaphoric counterpart to `-map'." |
|
|
|
|
(push ,form ,r)) |
|
|
|
|
(nreverse ,r)))) |
|
|
|
|
|
|
|
|
|
(defmacro --reduce-from (form initial-value list) |
|
|
|
|
"Anaphoric form of `-reduce-from'." |
|
|
|
|
(defmacro --reduce-from (form init list) |
|
|
|
|
"Accumulate a value by evaluating FORM across LIST. |
|
|
|
|
This macro is like `--each' (which see), but it additionally |
|
|
|
|
provides an accumulator variable `acc' which it successively |
|
|
|
|
binds to the result of evaluating FORM for the current LIST |
|
|
|
|
element before processing the next element. For the first |
|
|
|
|
element, `acc' is initialized with the result of evaluating INIT. |
|
|
|
|
The return value is the resulting value of `acc'. If LIST is |
|
|
|
|
empty, FORM is not evaluated, and the return value is the result |
|
|
|
|
of INIT. |
|
|
|
|
This is the anaphoric counterpart to `-reduce-from'." |
|
|
|
|
(declare (debug (form form form))) |
|
|
|
|
`(let ((acc ,initial-value)) |
|
|
|
|
`(let ((acc ,init)) |
|
|
|
|
(--each ,list (setq acc ,form)) |
|
|
|
|
acc)) |
|
|
|
|
|
|
|
|
|
(defun -reduce-from (fn initial-value list) |
|
|
|
|
"Return the result of applying FN to INITIAL-VALUE and the |
|
|
|
|
first item in LIST, then applying FN to that result and the 2nd |
|
|
|
|
item, etc. If LIST contains no items, return INITIAL-VALUE and |
|
|
|
|
do not call FN. |
|
|
|
|
(defun -reduce-from (fn init list) |
|
|
|
|
"Reduce the function FN across LIST, starting with INIT. |
|
|
|
|
Return the result of applying FN to INIT and the first element of |
|
|
|
|
LIST, then applying FN to that result and the second element, |
|
|
|
|
etc. If LIST is empty, return INIT without calling FN. |
|
|
|
|
|
|
|
|
|
In the anaphoric form `--reduce-from', the accumulated value is |
|
|
|
|
exposed as symbol `acc'. |
|
|
|
|
|
|
|
|
|
See also: `-reduce', `-reduce-r'" |
|
|
|
|
(--reduce-from (funcall fn acc it) initial-value list)) |
|
|
|
|
This function's anaphoric counterpart is `--reduce-from'. |
|
|
|
|
For other folds, see also `-reduce' and `-reduce-r'." |
|
|
|
|
(--reduce-from (funcall fn acc it) init list)) |
|
|
|
|
|
|
|
|
|
(defmacro --reduce (form list) |
|
|
|
|
"Anaphoric form of `-reduce'." |
|
|
|
|
"Accumulate a value by evaluating FORM across LIST. |
|
|
|
|
This macro is like `--reduce-from' (which see), except the first |
|
|
|
|
element of LIST is taken as INIT. Thus if LIST contains a single |
|
|
|
|
item, it is returned without evaluating FORM. If LIST is empty, |
|
|
|
|
FORM is evaluated with `it' and `acc' bound to nil. |
|
|
|
|
This is the anaphoric counterpart to `-reduce'." |
|
|
|
|
(declare (debug (form form))) |
|
|
|
|
(let ((lv (make-symbol "list-value"))) |
|
|
|
|
`(let ((,lv ,list)) |
|
|
|
|
(if ,lv |
|
|
|
|
(--reduce-from ,form (car ,lv) (cdr ,lv)) |
|
|
|
|
(let (acc it) ,form))))) |
|
|
|
|
(let (acc it) |
|
|
|
|
(ignore acc it) |
|
|
|
|
,form))))) |
|
|
|
|
|
|
|
|
|
(defun -reduce (fn list) |
|
|
|
|
"Return the result of applying FN to the first 2 items in LIST, |
|
|
|
|
then applying FN to that result and the 3rd item, etc. If LIST |
|
|
|
|
contains no items, return the result of calling FN with no |
|
|
|
|
arguments. If LIST contains a single item, return that item |
|
|
|
|
and do not call FN. |
|
|
|
|
|
|
|
|
|
In the anaphoric form `--reduce', the accumulated value is |
|
|
|
|
exposed as symbol `acc'. |
|
|
|
|
|
|
|
|
|
See also: `-reduce-from', `-reduce-r'" |
|
|
|
|
"Reduce the function FN across LIST. |
|
|
|
|
Return the result of applying FN to the first two elements of |
|
|
|
|
LIST, then applying FN to that result and the third element, etc. |
|
|
|
|
If LIST contains a single element, return it without calling FN. |
|
|
|
|
If LIST is empty, return the result of calling FN with no |
|
|
|
|
arguments. |
|
|
|
|
|
|
|
|
|
This function's anaphoric counterpart is `--reduce'. |
|
|
|
|
For other folds, see also `-reduce-from' and `-reduce-r'." |
|
|
|
|
(if list |
|
|
|
|
(-reduce-from fn (car list) (cdr list)) |
|
|
|
|
(funcall fn))) |
|
|
|
|
|
|
|
|
|
(defmacro --reduce-r-from (form initial-value list) |
|
|
|
|
"Anaphoric version of `-reduce-r-from'." |
|
|
|
|
(defmacro --reduce-r-from (form init list) |
|
|
|
|
"Accumulate a value by evaluating FORM across LIST in reverse. |
|
|
|
|
This macro is like `--reduce-from', except it starts from the end |
|
|
|
|
of LIST. |
|
|
|
|
This is the anaphoric counterpart to `-reduce-r-from'." |
|
|
|
|
(declare (debug (form form form))) |
|
|
|
|
`(--reduce-from ,form ,initial-value (reverse ,list))) |
|
|
|
|
`(let ((acc ,init)) |
|
|
|
|
(--each-r ,list (setq acc ,form)) |
|
|
|
|
acc)) |
|
|
|
|
|
|
|
|
|
(defun -reduce-r-from (fn initial-value list) |
|
|
|
|
"Replace conses with FN, nil with INITIAL-VALUE and evaluate |
|
|
|
|
the resulting expression. If LIST is empty, INITIAL-VALUE is |
|
|
|
|
returned and FN is not called. |
|
|
|
|
(defun -reduce-r-from (fn init list) |
|
|
|
|
"Reduce the function FN across LIST in reverse, starting with INIT. |
|
|
|
|
Return the result of applying FN to the last element of LIST and |
|
|
|
|
INIT, then applying FN to the second-to-last element and the |
|
|
|
|
previous result of FN, etc. That is, the first argument of FN is |
|
|
|
|
the current element, and its second argument the accumulated |
|
|
|
|
value. If LIST is empty, return INIT without calling FN. |
|
|
|
|
|
|
|
|
|
Note: this function works the same as `-reduce-from' but the |
|
|
|
|
operation associates from right instead of from left. |
|
|
|
|
This function is like `-reduce-from' but the operation associates |
|
|
|
|
from the right rather than left. In other words, it starts from |
|
|
|
|
the end of LIST and flips the arguments to FN. Conceptually, it |
|
|
|
|
is like replacing the conses in LIST with applications of FN, and |
|
|
|
|
its last link with INIT, and evaluating the resulting expression. |
|
|
|
|
|
|
|
|
|
See also: `-reduce-r', `-reduce'" |
|
|
|
|
(--reduce-r-from (funcall fn it acc) initial-value list)) |
|
|
|
|
This function's anaphoric counterpart is `--reduce-r-from'. |
|
|
|
|
For other folds, see also `-reduce-r' and `-reduce'." |
|
|
|
|
(--reduce-r-from (funcall fn it acc) init list)) |
|
|
|
|
|
|
|
|
|
(defmacro --reduce-r (form list) |
|
|
|
|
"Anaphoric version of `-reduce-r'." |
|
|
|
|
"Accumulate a value by evaluating FORM across LIST in reverse order. |
|
|
|
|
This macro is like `--reduce', except it starts from the end of |
|
|
|
|
LIST. |
|
|
|
|
This is the anaphoric counterpart to `-reduce-r'." |
|
|
|
|
(declare (debug (form form))) |
|
|
|
|
`(--reduce ,form (reverse ,list))) |
|
|
|
|
|
|
|
|
|
(defun -reduce-r (fn list) |
|
|
|
|
"Replace conses with FN and evaluate the resulting expression. |
|
|
|
|
The final nil is ignored. If LIST contains no items, return the |
|
|
|
|
result of calling FN with no arguments. If LIST contains a single |
|
|
|
|
item, return that item and do not call FN. |
|
|
|
|
|
|
|
|
|
The first argument of FN is the new item, the second is the |
|
|
|
|
accumulated value. |
|
|
|
|
|
|
|
|
|
Note: this function works the same as `-reduce' but the operation |
|
|
|
|
associates from right instead of from left. |
|
|
|
|
|
|
|
|
|
See also: `-reduce-r-from', `-reduce'" |
|
|
|
|
"Reduce the function FN across LIST in reverse. |
|
|
|
|
Return the result of applying FN to the last two elements of |
|
|
|
|
LIST, then applying FN to the third-to-last element and the |
|
|
|
|
previous result of FN, etc. That is, the first argument of FN is |
|
|
|
|
the current element, and its second argument the accumulated |
|
|
|
|
value. If LIST contains a single element, return it without |
|
|
|
|
calling FN. If LIST is empty, return the result of calling FN |
|
|
|
|
with no arguments. |
|
|
|
|
|
|
|
|
|
This function is like `-reduce' but the operation associates from |
|
|
|
|
the right rather than left. In other words, it starts from the |
|
|
|
|
end of LIST and flips the arguments to FN. Conceptually, it is |
|
|
|
|
like replacing the conses in LIST with applications of FN, |
|
|
|
|
ignoring its last link, and evaluating the resulting expression. |
|
|
|
|
|
|
|
|
|
This function's anaphoric counterpart is `--reduce-r'. |
|
|
|
|
For other folds, see also `-reduce-r-from' and `-reduce'." |
|
|
|
|
(if list |
|
|
|
|
(--reduce-r (funcall fn it acc) list) |
|
|
|
|
(funcall fn))) |
|
|
|
|
|
|
|
|
|
(defun -reductions-from (fn init list) |
|
|
|
|
"Return a list of the intermediate values of the reduction. |
|
|
|
|
|
|
|
|
|
See `-reduce-from' for explanation of the arguments. |
|
|
|
|
(defmacro --reductions-from (form init list) |
|
|
|
|
"Return a list of FORM's intermediate reductions across LIST. |
|
|
|
|
That is, a list of the intermediate values of the accumulator |
|
|
|
|
when `--reduce-from' (which see) is called with the same |
|
|
|
|
arguments. |
|
|
|
|
This is the anaphoric counterpart to `-reductions-from'." |
|
|
|
|
(declare (debug (form form form))) |
|
|
|
|
`(nreverse |
|
|
|
|
(--reduce-from (cons (let ((acc (car acc))) (ignore acc) ,form) acc) |
|
|
|
|
(list ,init) |
|
|
|
|
,list))) |
|
|
|
|
|
|
|
|
|
See also: `-reductions', `-reductions-r', `-reduce-r'" |
|
|
|
|
(nreverse (--reduce-from (cons (funcall fn (car acc) it) acc) (list init) list))) |
|
|
|
|
(defun -reductions-from (fn init list) |
|
|
|
|
"Return a list of FN's intermediate reductions across LIST. |
|
|
|
|
That is, a list of the intermediate values of the accumulator |
|
|
|
|
when `-reduce-from' (which see) is called with the same |
|
|
|
|
arguments. |
|
|
|
|
This function's anaphoric counterpart is `--reductions-from'. |
|
|
|
|
For other folds, see also `-reductions' and `-reductions-r'." |
|
|
|
|
(--reductions-from (funcall fn acc it) init list)) |
|
|
|
|
|
|
|
|
|
(defmacro --reductions (form list) |
|
|
|
|
"Return a list of FORM's intermediate reductions across LIST. |
|
|
|
|
That is, a list of the intermediate values of the accumulator |
|
|
|
|
when `--reduce' (which see) is called with the same arguments. |
|
|
|
|
This is the anaphoric counterpart to `-reductions'." |
|
|
|
|
(declare (debug (form form))) |
|
|
|
|
(let ((lv (make-symbol "list-value"))) |
|
|
|
|
`(let ((,lv ,list)) |
|
|
|
|
(if ,lv |
|
|
|
|
(--reductions-from ,form (car ,lv) (cdr ,lv)) |
|
|
|
|
(let (acc it) |
|
|
|
|
(ignore acc it) |
|
|
|
|
(list ,form)))))) |
|
|
|
|
|
|
|
|
|
(defun -reductions (fn list) |
|
|
|
|
"Return a list of the intermediate values of the reduction. |
|
|
|
|
|
|
|
|
|
See `-reduce' for explanation of the arguments. |
|
|
|
|
|
|
|
|
|
See also: `-reductions-from', `-reductions-r', `-reduce-r'" |
|
|
|
|
(and list (-reductions-from fn (car list) (cdr list)))) |
|
|
|
|
"Return a list of FN's intermediate reductions across LIST. |
|
|
|
|
That is, a list of the intermediate values of the accumulator |
|
|
|
|
when `-reduce' (which see) is called with the same arguments. |
|
|
|
|
This function's anaphoric counterpart is `--reductions'. |
|
|
|
|
For other folds, see also `-reductions' and `-reductions-r'." |
|
|
|
|
(if list |
|
|
|
|
(--reductions-from (funcall fn acc it) (car list) (cdr list)) |
|
|
|
|
(list (funcall fn)))) |
|
|
|
|
|
|
|
|
|
(defmacro --reductions-r-from (form init list) |
|
|
|
|
"Return a list of FORM's intermediate reductions across reversed LIST. |
|
|
|
|
That is, a list of the intermediate values of the accumulator |
|
|
|
|
when `--reduce-r-from' (which see) is called with the same |
|
|
|
|
arguments. |
|
|
|
|
This is the anaphoric counterpart to `-reductions-r-from'." |
|
|
|
|
(declare (debug (form form form))) |
|
|
|
|
`(--reduce-r-from (cons (let ((acc (car acc))) (ignore acc) ,form) acc) |
|
|
|
|
(list ,init) |
|
|
|
|
,list)) |
|
|
|
|
|
|
|
|
|
(defun -reductions-r-from (fn init list) |
|
|
|
|
"Return a list of the intermediate values of the reduction. |
|
|
|
|
|
|
|
|
|
See `-reduce-r-from' for explanation of the arguments. |
|
|
|
|
|
|
|
|
|
See also: `-reductions-r', `-reductions', `-reduce'" |
|
|
|
|
(--reduce-r-from (cons (funcall fn it (car acc)) acc) (list init) list)) |
|
|
|
|
"Return a list of FN's intermediate reductions across reversed LIST. |
|
|
|
|
That is, a list of the intermediate values of the accumulator |
|
|
|
|
when `-reduce-r-from' (which see) is called with the same |
|
|
|
|
arguments. |
|
|
|
|
This function's anaphoric counterpart is `--reductions-r-from'. |
|
|
|
|
For other folds, see also `-reductions' and `-reductions-r'." |
|
|
|
|
(--reductions-r-from (funcall fn it acc) init list)) |
|
|
|
|
|
|
|
|
|
(defmacro --reductions-r (form list) |
|
|
|
|
"Return a list of FORM's intermediate reductions across reversed LIST. |
|
|
|
|
That is, a list of the intermediate values of the accumulator |
|
|
|
|
when `--reduce-re' (which see) is called with the same arguments. |
|
|
|
|
This is the anaphoric counterpart to `-reductions-r'." |
|
|
|
|
(declare (debug (form list))) |
|
|
|
|
(let ((lv (make-symbol "list-value"))) |
|
|
|
|
`(let ((,lv (reverse ,list))) |
|
|
|
|
(if ,lv |
|
|
|
|
(--reduce-from (cons (let ((acc (car acc))) (ignore acc) ,form) acc) |
|
|
|
|
(list (car ,lv)) |
|
|
|
|
(cdr ,lv)) |
|
|
|
|
(let (acc it) |
|
|
|
|
(ignore acc it) |
|
|
|
|
(list ,form)))))) |
|
|
|
|
|
|
|
|
|
(defun -reductions-r (fn list) |
|
|
|
|
"Return a list of the intermediate values of the reduction. |
|
|
|
|
|
|
|
|
|
See `-reduce-r' for explanation of the arguments. |
|
|
|
|
|
|
|
|
|
See also: `-reductions-r-from', `-reductions', `-reduce'" |
|
|
|
|
(when list |
|
|
|
|
(let ((rev (reverse list))) |
|
|
|
|
(--reduce-from (cons (funcall fn it (car acc)) acc) |
|
|
|
|
(list (car rev)) |
|
|
|
|
(cdr rev))))) |
|
|
|
|
"Return a list of FN's intermediate reductions across reversed LIST. |
|
|
|
|
That is, a list of the intermediate values of the accumulator |
|
|
|
|
when `-reduce-r' (which see) is called with the same arguments. |
|
|
|
|
This function's anaphoric counterpart is `--reductions-r'. |
|
|
|
|
For other folds, see also `-reductions-r-from' and |
|
|
|
|
`-reductions'." |
|
|
|
|
(if list |
|
|
|
|
(--reductions-r (funcall fn it acc) list) |
|
|
|
|
(list (funcall fn)))) |
|
|
|
|
|
|
|
|
|
(defmacro --filter (form list) |
|
|
|
|
"Anaphoric form of `-filter'. |
|
|
|
|
@ -2851,6 +2940,10 @@ structure such as plist or alist." |
|
|
|
|
"--reduce-from" |
|
|
|
|
"--reduce-r" |
|
|
|
|
"--reduce-r-from" |
|
|
|
|
"--reductions" |
|
|
|
|
"--reductions-from" |
|
|
|
|
"--reductions-r" |
|
|
|
|
"--reductions-r-from" |
|
|
|
|
"--remove" |
|
|
|
|
"--remove-first" |
|
|
|
|
"--remove-last" |
|
|
|
|
|