@ -4,7 +4,7 @@
;; Author: Magnar Sveen <magnars@gmail.com>
;; Version: 2.14.1
;; Package-Version: 201809 03.1042
;; Package-Version: 201809 10.1856
;; Keywords: lists
;; This program is free software; you can redistribute it and/or modify
@ -206,7 +206,7 @@ Return nil, used for side-effects only."
" 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
FN is not called .
do not call FN .
In the anaphoric form ` --reduce-from ', the accumulated value is
exposed as symbol ` acc '.
@ -226,9 +226,9 @@ See also: `-reduce', `-reduce-r'"
( 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, FN must accept no arguments as well, and
reduce return the result of calling FN with no arguments. If
LIST has only 1 item, it is returned and FN is not called .
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 '.
@ -238,6 +238,11 @@ See also: `-reduce-from', `-reduce-r'"
( -reduce-from fn ( car list ) ( cdr list ) )
( funcall fn ) ) )
( defmacro --reduce-r-from ( form initial-value list )
" Anaphoric version of `-reduce-r-from' . "
( declare ( debug ( form form form ) ) )
` ( --reduce-from , form , initial-value ( reverse , list ) ) )
( 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
@ -247,20 +252,18 @@ Note: this function works the same as `-reduce-from' but the
operation associates from right instead of from left.
See also: ` -reduce-r ', ` -reduce ' "
( if ( not list ) initial-value
( funcall fn ( car list ) ( -reduce-r-from fn initial-value ( cdr list ) ) ) ) )
( --reduce-r-from ( funcall fn it acc ) initial-value list ) )
( defmacro --reduce-r -from ( form initial-value list )
" Anaphoric version of `-reduce-r -from '. "
( declare ( debug ( form form form ) ) )
` ( - reduce-r-from ( lambda ( &optional it acc ) , form ) , initial-value , list ) )
( defmacro --reduce-r ( form list )
" Anaphoric version of `-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, FN must
accept no arguments as well, and reduce return the result of
calling FN with no arguments. If LIST has only 1 item, it is
returned and FN is not called.
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.
@ -269,15 +272,9 @@ Note: this function works the same as `-reduce' but the operation
associates from right instead of from left.
See also: ` -reduce-r-from ', ` -reduce ' "
( cond
( ( not list ) ( funcall fn ) )
( ( not ( cdr list ) ) ( car list ) )
( t ( funcall fn ( car list ) ( -reduce-r fn ( cdr list ) ) ) ) ) )
( defmacro --reduce-r ( form list )
" Anaphoric version of `-reduce-r' . "
( declare ( debug ( form form ) ) )
` ( -reduce-r ( lambda ( &optional it acc ) , form ) , list ) )
( 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.
@ -293,7 +290,7 @@ See also: `-reductions', `-reductions-r', `-reduce-r'"
See ` -reduce ' for explanation of the arguments.
See also: ` -reductions-from ', ` -reductions-r ', ` -reduce-r ' "
( -reductions-from fn ( car list ) ( cdr list ) ) )
( and list ( -reductions-from fn ( car list ) ( cdr list ) ) ) )
( defun -reductions-r-from ( fn init list )
" Return a list of the intermediate values of the reduction.
@ -309,7 +306,11 @@ See also: `-reductions-r', `-reductions', `-reduce'"
See ` -reduce-r ' for explanation of the arguments.
See also: ` -reductions-r-from ', ` -reductions ', ` -reduce ' "
( -reductions-r-from fn ( -last-item list ) ( -butlast list ) ) )
( when list
( let ( ( rev ( reverse list ) ) )
( --reduce-from ( cons ( funcall fn it ( car acc ) ) acc )
( list ( car rev ) )
( cdr rev ) ) ) ) )
( defmacro --filter ( form list )
" Anaphoric form of `-filter' .
@ -2311,6 +2312,10 @@ or with `-compare-fn' if that's non-nil."
( --reduce ( --take-while ( and acc ( equal ( pop acc ) it ) ) it )
lists ) )
( defun -common-suffix ( &rest lists )
" Return the longest common suffix of LISTS. "
( nreverse ( apply #' -common-prefix ( mapcar #' reverse lists ) ) ) )
( defun -contains? ( list element )
" Return non-nil if LIST contains ELEMENT.
@ -2905,6 +2910,7 @@ structure such as plist or alist."
" -inits "
" -tails "
" -common-prefix "
" -common-suffix "
" -contains? "
" -contains-p "
" -same-items? "