diff options
author | colin <colin@cicadas.surf> | 2024-06-17 21:13:41 -0700 |
---|---|---|
committer | colin <colin@cicadas.surf> | 2024-06-17 21:13:41 -0700 |
commit | 22686584f103d163a1e5f370aa06905ec5c3b4a4 (patch) | |
tree | 9d9905cda18a52e82c751d4820865da0b3d2e50c /util.lisp |
Inital Commit
Diffstat (limited to 'util.lisp')
-rw-r--r-- | util.lisp | 36 |
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))))) |