;; group alone items that are evaluated "t" and group multiple items in sequence that are evaluated "nil" by specified function
;;
;; (setq L1 '("ABC" 1 "A" "B" -2 "CDE" 525 "D" 3 "E" "F")) ; Given List 1
;;
;; (foo1 (function (lambda ( x ) (= "CDE" x))) L1) -> '(("ABC" 1 "A" "B" -2) ("CDE") (525 "D" 3 "E" "F"))
;; (foo1 (function numberp) L1) -> '(("ABC") (1) ("A" "B") (-2) ("CDE") (525) ("D") (3) ("E" "F"))
;; (foo1 (function minusp) L1) -> '(("ABC" 1 "A" "B") (-2) ("CDE" 525 "D" 3 "E" "F"))
;; (foo1 (function (lambda ( x ) (member x '("A" "D")))) L1) -> '(("ABC" 1) ("A") ("B" -2 "CDE" 525) ("D") (3 "E" "F"))
(defun foo1
( prd lst
/ rtn tmp err
) )
)
)
;; group alone items that are evaluated "nil" and group multiple items in sequence that are evaluated "t" by specified function
;;
;; (setq L2 '("ABC" 1 "A" "B" -2 -5 10 "CDE" 525 "D" 3 "E" "F")) ; Given List 2
;;
;; (foo2 (function (lambda ( x ) (= "CDE" x))) L2) -> '(("ABC") (1) ("A") ("B)" (-2) (-5) (10) ("CDE") (525) ("D") (3) ("E") ("F"))
;; (foo2 (function numberp) L2) -> '(("ABC") (1) ("A") ("B") (-2 -5 10) ("CDE") (525) ("D") (3) ("E") ("F"))
;; (foo2 (function minusp) L2) -> '(("ABC") (1) ("A") ("B") (-2 -5) (10) ("CDE") (525) ("D") (3) ("E") ("F"))
;; (foo2 (function (lambda ( x ) (member x '("A" "D")))) L2) -> '(("ABC") (1) ("A") ("B") (-2) (-5) (10) ("CDE") (525) ("D") (3) ("E") ("F"))
(defun foo2
( prd lst
/ rtn tmp err
) )
)
)
;; note that foo1 and foo2 are the same, only inside if (then) (else) are swithched...
;; acquire items that are evaluated "t" and remove items evaluated "nil" by specified function
;;
;; (setq L3 '("ABC" 1 "A" "B" -2 "CDE" 525 "D" 3 "E" "F")) ; Given List 3
;;
;; (foo3 (function (lambda ( x ) (= "CDE" x))) L3) -> '("CDE")
;; (foo3 (function numberp) L3) -> '(1 -2 525 3)
;; (foo3 (function minusp) L3) -> '(-2)
;; (foo3 (function (lambda ( x ) (member x '("A" "D")))) L3) -> '("A" "D")
(defun foo3
( prd lst
/ rtn err
) )
)
)
(vl
-remove
-if
-not prd lst
) )
;; this shortcut foo3 won't work correctly for (foo3 (function minusp) L3) - it will error : ; error: bad argument type: numberp: "ABC", so function must be specified differently (foo3 (function (lambda ( x ) (and (numberp x) (minusp x)))) L3)
;; acquire items that are evaluated "nil" and remove items evaluated "t" by specified function
;;
;; (setq L4 '("ABC" 1 "A" "B" -2 -5 10 "CDE" 525 "D" 3 "E" "F")) ; Given List 4
;;
;; (foo4 (function (lambda ( x ) (= "CDE" x))) L4) -> '("ABC" 1 "A" "B" -2 -5 10 525 "D" 3 "E" "F")
;; (foo4 (function numberp) L4) -> '("ABC" "A" "B" "CDE" "D" "E" "F")
;; (foo4 (function minusp) L4) -> '("ABC" 1 "A" "B" 10 "CDE" 525 "D" 3 "E" "F")
;; (foo4 (function (lambda ( x ) (member x '("A" "D")))) L4) -> '("ABC" 1 "B" -2 -5 10 "CDE" 525 3 "E" "F")
(defun foo4
( prd lst
/ rtn err
) )
)
)
)
;; this shortcut foo4 won't work correctly for (foo4 (function minusp) L4) - it will error : ; error: bad argument type: numberp: "ABC", so function must be specified differently (foo4 (function (lambda ( x ) (and (numberp x) (minusp x)))) L4)
;; note that foo3 and foo4 are the same, only if condition is opposite thus (not) before condition of foo3 in foo4 - in additional short variants function is opposite...