X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=src%2Futils.lisp;h=d586cddf69dd01913e077e8d824d242e5fa1a2c0;hb=68cd2db6542fa3442d46b0331ecf8be8f86c09c2;hp=73fc55126b99818530de9c1245b142cc36413b6c;hpb=8464d7110c70c0056a45b1076cc2f50971e0b5d7;p=jscl.git diff --git a/src/utils.lisp b/src/utils.lisp index 73fc551..d586cdd 100644 --- a/src/utils.lisp +++ b/src/utils.lisp @@ -16,7 +16,8 @@ ;; You should have received a copy of the GNU General Public License ;; along with JSCL. If not, see . -(defvar *newline* (string (code-char 10))) +(defvar *newline* " +") (defmacro concatf (variable &body form) `(setq ,variable (concat ,variable (progn ,@form)))) @@ -28,18 +29,18 @@ 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 "")) - (!reduce (lambda (s o) (concat s separator o)) - (cdr list) - :initial-value (car list))) + (if (null list) + "" + (!reduce (lambda (s o) (concat s separator o)) + (cdr list) + (car list)))) (defun join-trailing (list &optional (separator "")) (if (null list)