From 7f5bf57bb7837297e531968713250158fad0c7b3 Mon Sep 17 00:00:00 2001 From: David Vazquez Date: Sat, 12 Jan 2013 13:22:47 +0000 Subject: [PATCH] Common Lisp `indent' version to speed up bootstrap --- ecmalisp.lisp | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/ecmalisp.lisp b/ecmalisp.lisp index 7d92ef4..1754c19 100644 --- a/ecmalisp.lisp +++ b/ecmalisp.lisp @@ -481,25 +481,40 @@ "" (concat (car list) separator (join-trailing (cdr list) separator)))) -;;; Like CONCAT, but prefix each line with four spaces. + +;;; Like CONCAT, but prefix each line with four spaces. Two versions +;;; of this function are available, because the Ecmalisp version is +;;; very slow and bootstraping was annoying. + +#+ecmalisp (defun indent (&rest string) (let ((input (join string))) (let ((output "") (index 0) (size (length input))) - (when (plusp size) - (setq output " ")) + (when (plusp (length input)) (concatf output " ")) (while (< index size) - (setq output - (concat output - (if (and (char= (char input index) #\newline) - (< index (1- size)) - (not (char= (char input (1+ index)) #\newline))) - (concat (string #\newline) " ") - (subseq input index (1+ index))))) + (let ((str + (if (and (char= (char input index) #\newline) + (< index (1- size)) + (not (char= (char input (1+ index)) #\newline))) + (concat (string #\newline) " ") + (string (char input index))))) + (concatf output str)) (incf index)) output))) +#+common-lisp +(defun indent (&rest string) + (with-output-to-string (*standard-output*) + (with-input-from-string (input (join string)) + (loop + for line = (read-line input nil) + while line + do (write-string " ") + do (write-line line))))) + + (defun integer-to-string (x) (cond ((zerop x) -- 1.7.10.4