summaryrefslogtreecommitdiff
path: root/util.lisp
diff options
context:
space:
mode:
Diffstat (limited to 'util.lisp')
-rw-r--r--util.lisp36
1 files changed, 36 insertions, 0 deletions
diff --git a/util.lisp b/util.lisp
new file mode 100644
index 0000000..537d85d
--- /dev/null
+++ b/util.lisp
@@ -0,0 +1,36 @@
+(in-package #:def)
+
+
+(defun take-until (pred list)
+ "Returns two values: FRONT BACK.
+
+FRONT contains the first N members X of LIST for which (PRED X) is NIL.
+BACK contains everything after the members of FRONT.
+
+(EQUALP LIST
+ (MULTIPLE-VALUE-BIND (FRONT BACK) (TAKE-UNTIL PRED LIST)
+ (APPEND FRONT BACK))
+
+Is always T."
+ (loop :for (x . back) :on list
+ :for fx? := (funcall pred x)
+ :until fx?
+ :collect x :into front
+ :finally (return (values front (if fx? (cons x back) nil)))))
+
+(defun partition (pred list)
+ "Returns two list values: YES NO.
+
+YES is everything for which PRED is T, NO is everything else."
+ (loop :for e :in list
+ :when (funcall pred e)
+ :collect e :into yes
+ :else
+ :collect e :into no
+ :finally (return (values yes no))))
+
+(defun good-muffed-var-name-p (name &key (muffer "*"))
+ (and (symbolp name)
+ (string= muffer name :end2 (length muffer))
+ (string= muffer name :start2 (- (length (symbol-name name))
+ (length muffer)))))