-
Notifications
You must be signed in to change notification settings - Fork 0
/
predicate.lisp
34 lines (28 loc) · 1.03 KB
/
predicate.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
;;;; org.unaen.cl.util/predicate.lisp
(uiop:define-package #:org.unaen.cl.util/predicate
(:use #:common-lisp)
(:export #:separate-if
#:truth
#:false))
(in-package #:org.unaen.cl.util/predicate)
(defgeneric separate-if (predicate-function sequence &rest rest)
(:documentation "Separate into not matching and matching lists according to
the predicate-function.")
(:method ((predicate function) (sequence sequence) &rest rest)
(let ((matched (list)))
(values (apply #'remove-if
#'(lambda (x)
(let ((it (funcall predicate x)))
(unless it
(push x matched))))
sequence
rest)
(nreverse matched)))))
(defun truth (ignored-var)
"Accept a single required value and always return true."
(declare (ignore ignored-var))
t)
(defun false (ignored-var)
"Accept a single required value and always return false."
(declare (ignore ignored-var))
nil)