X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=src%2Futils.lisp;h=6ab351d1f21fc9a780a442638e685eb9ee727011;hb=29c5587e4ad81dd1442c5f54cc686a45f7cb9d2e;hp=41fe5f3676eb80c6641fbc399036e1eadfc5cf37;hpb=b3c22837d022f29e077bc65d74cc1b320c91ba65;p=jscl.git diff --git a/src/utils.lisp b/src/utils.lisp index 41fe5f3..6ab351d 100644 --- a/src/utils.lisp +++ b/src/utils.lisp @@ -16,8 +16,7 @@ ;; You should have received a copy of the GNU General Public License ;; along with JSCL. If not, see . -(defvar *newline* " -") +(/debug "loading utils.lisp!") (defmacro concatf (variable &body form) `(setq ,variable (concat ,variable (progn ,@form)))) @@ -84,3 +83,21 @@ (defun float-to-string (x) #+jscl (float-to-string x) #-jscl (format nil "~f" x)) + +(defun satisfies-test-p (x y &key key (test #'eql) testp (test-not #'eql) test-not-p) + (when (and testp test-not-p) + (error "Both test and test-not are set")) + (let ((key-val (if key (funcall key y) y)) + (fn (if test-not-p (complement test-not) test))) + (funcall fn x key-val))) + + +(defun interleave (list element &optional after-last-p) + (unless (null list) + (with-collect + (collect (car list)) + (dolist (x (cdr list)) + (collect element) + (collect x)) + (when after-last-p + (collect element)))))