X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=src%2Futils.lisp;h=41fe5f3676eb80c6641fbc399036e1eadfc5cf37;hb=fde8e7678f3a194026bf14d630d3b7e979e3ce6e;hp=224fcb276b3fedc5ba1fe8a1b0654deb75e8e9fd;hpb=9d33365d682c38487dd922d995e65ef53e14c2c7;p=jscl.git diff --git a/src/utils.lisp b/src/utils.lisp index 224fcb2..41fe5f3 100644 --- a/src/utils.lisp +++ b/src/utils.lisp @@ -23,26 +23,24 @@ `(setq ,variable (concat ,variable (progn ,@form)))) ;;; This couple of helper functions will be defined in both Common -;;; Lisp and in Ecmalisp. +;;; Lisp and in JSCL (defun ensure-list (x) (if (listp x) x (list x))) -(defun !reduce (func list &key initial-value) - (if (null list) - initial-value - (!reduce func - (cdr list) - :initial-value (funcall func initial-value (car list))))) +(defun !reduce (func list initial-value) + (let ((result initial-value)) + (dolist (element list result) + (setq result (funcall func result element))))) ;;; Concatenate a list of strings, with a separator (defun join (list &optional (separator "")) (if (null list) "" - (!reduce (lambda (s o) (concat s separator o)) - (cdr list) - :initial-value (car list)))) + (!reduce (lambda (s o) (concat s separator o)) + (cdr list) + (car list)))) (defun join-trailing (list &optional (separator "")) (if (null list) @@ -85,4 +83,4 @@ (defun float-to-string (x) #+jscl (float-to-string x) - #+common-lisp (format nil "~f" x)) + #-jscl (format nil "~f" x))