From 22686584f103d163a1e5f370aa06905ec5c3b4a4 Mon Sep 17 00:00:00 2001 From: colin Date: Mon, 17 Jun 2024 21:13:41 -0700 Subject: Inital Commit --- util.lisp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 util.lisp (limited to 'util.lisp') 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))))) -- cgit v1.2.3