X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=src%2Futils.lisp;h=d586cddf69dd01913e077e8d824d242e5fa1a2c0;hb=68cd2db6542fa3442d46b0331ecf8be8f86c09c2;hp=31afe285604e5429191926074f6ab997053baf14;hpb=261c79ce0f1b20b7f917a4139239facbd3e89eed;p=jscl.git diff --git a/src/utils.lisp b/src/utils.lisp index 31afe28..d586cdd 100644 --- a/src/utils.lisp +++ b/src/utils.lisp @@ -3,20 +3,21 @@ ;; Copyright (C) 2012, 2013 David Vazquez ;; Copyright (C) 2012 Raimon Grau -;; This program is free software: you can redistribute it and/or +;; JSCL is free software: you can redistribute it and/or ;; modify it under the terms of the GNU General Public License as ;; published by the Free Software Foundation, either version 3 of the ;; License, or (at your option) any later version. ;; -;; This program is distributed in the hope that it will be useful, but +;; JSCL is distributed in the hope that it will be useful, but ;; WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;; General Public License for more details. ;; ;; You should have received a copy of the GNU General Public License -;; along with this program. If not, see . +;; 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,24 +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 "")) - (cond - ((null list) - "") - ((null (cdr list)) - (car list)) - (t - (concat (car list) - separator - (join (cdr list) separator))))) + (if (null list) + "" + (!reduce (lambda (s o) (concat s separator o)) + (cdr list) + (car list)))) (defun join-trailing (list &optional (separator "")) (if (null list) @@ -85,3 +80,7 @@ (setq x (truncate x 10))) (mapconcat (lambda (x) (string (digit-char x))) digits))))) + +(defun float-to-string (x) + #+jscl (float-to-string x) + #+common-lisp (format nil "~f" x))