r4822: *** empty log message ***
authorKevin M. Rosenberg <kevin@rosenberg.net>
Tue, 6 May 2003 01:43:14 +0000 (01:43 +0000)
committerKevin M. Rosenberg <kevin@rosenberg.net>
Tue, 6 May 2003 01:43:14 +0000 (01:43 +0000)
buff-input.lisp
lists.lisp
package.lisp
seqs.lisp
strings.lisp
tests.lisp

index f0802bc0bff2b141479a24a27668c0c7ab7fbf57..d17590dc0f29790645575155477a01c70908ef4b 100644 (file)
@@ -7,7 +7,7 @@
 ;;;; Programmer:    Kevin M. Rosenberg
 ;;;; Date Started:  Apr 2000
 ;;;;
-;;;; $Id: buff-input.lisp,v 1.5 2003/05/05 19:54:14 kevin Exp $
+;;;; $Id: buff-input.lisp,v 1.6 2003/05/06 01:43:14 kevin Exp $
 ;;;;
 ;;;; This file, part of KMRCL, is Copyright (c) 2002 by Kevin M. Rosenberg
 ;;;;
@@ -40,7 +40,8 @@
       (setf (aref bufs i) (make-array max-field-len :element-type 'character :fill-pointer 0 :adjustable nil)))
     bufs))
 
-(defun read-buffered-fields (fields strm &optional (field-delim +field-delim+))
+(defun read-buffered-fields (fields strm &optional (field-delim +field-delim+)
+                            (eof 'eof))
   "Read a line from a stream into a field buffers"
   (declare (type base-char field-delim)
           (type vector fields))
index ef134538c9e49af564b88df2ff5e7b1cf0c01841..a7ae3d1655f197fd5142a335c0b093e2f91a3ec8 100644 (file)
@@ -7,7 +7,7 @@
 ;;;; Programmer:    Kevin M. Rosenberg
 ;;;; Date Started:  Apr 2000
 ;;;;
-;;;; $Id: lists.lisp,v 1.2 2003/05/02 22:30:26 kevin Exp $
+;;;; $Id: lists.lisp,v 1.3 2003/05/06 01:43:14 kevin Exp $
 ;;;;
 ;;;; This file, part of KMRCL, is Copyright (c) 2002 by Kevin M. Rosenberg
 ;;;;
                       :key #'symbol-name :test 'equal)
        append (list name val)))
 
+(defun mapappend (func seq)
+  (apply #'append (mapcar func seq)))
+
+(defun mapcar-append-string-nontailrec (func v)
+  "Concatenate results of mapcar lambda calls"  
+  (aif (car v)
+       (concatenate 'string (funcall func it)
+                   (mapcar-append-string-nontailrec func (cdr v)))
+       ""))
+
+
+(defun mapcar-append-string (func v &optional (accum ""))
+  "Concatenate results of mapcar lambda calls"  
+  (aif (car v)
+       (mapcar-append-string 
+       func 
+       (cdr v) 
+       (concatenate 'string accum (funcall func it)))
+       accum))
+
+(defun mapcar2-append-string-nontailrec (func la lb)
+  "Concatenate results of mapcar lambda call's over two lists"  
+  (let ((a (car la))
+       (b (car lb)))
+    (if (and a b)
+      (concatenate 'string (funcall func a b)
+                  (mapcar2-append-string-nontailrec func (cdr la) (cdr lb)))
+      "")))
+  
+(defun mapcar2-append-string (func la lb &optional (accum ""))
+  "Concatenate results of mapcar lambda call's over two lists"  
+  (let ((a (car la))
+       (b (car lb)))
+    (if (and a b)
+       (mapcar2-append-string 
+        func 
+        (cdr la) 
+        (cdr lb)
+        (concatenate 'string accum (funcall func a b)))
+      accum)))
+
+(defun append-sublists (list)
+  "Takes a list of lists and appends all sublists"
+  (let ((results (car list)))
+    (dolist (elem (cdr list))
+      (setq results (append results elem)))
+    results))
 
index a2d3e28636dc84ebf82ca463294bf6b429fbd3dd..5a705ca44c72320eb792bac461f6c83a0f480992 100644 (file)
@@ -7,7 +7,7 @@
 ;;;; Programmer:    Kevin M. Rosenberg
 ;;;; Date Started:  Apr 2000
 ;;;;
-;;;; $Id: package.lisp,v 1.26 2003/05/05 21:36:50 kevin Exp $
+;;;; $Id: package.lisp,v 1.27 2003/05/06 01:43:14 kevin Exp $
 ;;;;
 ;;;; This file, part of KMRCL, is Copyright (c) 2002 by Kevin M. Rosenberg
 ;;;;
@@ -42,6 +42,7 @@
    #:delimited-string-to-list
    #:list-to-delimited-string
    #:flatten
+   #:append-sublists
    #:indent-spaces
    #:print-list
    #:print-rows
@@ -95,6 +96,8 @@
    #:substitute-chars-strings
    #:add-sql-quotes
    #:escape-backslashes
+   #:concat-separated-strings
+   #:print-separated-strings
    
    ;; symbols.lisp
    #:ensure-keyword
index b2a7508282785cf78acbcc3fb1a2747e1a1a1337..2e261bd1ac30859c39284fa73a92d5ce36ed5333 100644 (file)
--- a/seqs.lisp
+++ b/seqs.lisp
@@ -7,7 +7,7 @@
 ;;;; Programmer:    Kevin M. Rosenberg
 ;;;; Date Started:  Apr 2000
 ;;;;
-;;;; $Id: seqs.lisp,v 1.3 2003/05/04 15:09:59 kevin Exp $
+;;;; $Id: seqs.lisp,v 1.4 2003/05/06 01:43:14 kevin Exp $
 ;;;;
 ;;;; This file, part of KMRCL, is Copyright (c) 2002 by Kevin M. Rosenberg
 ;;;;
 (in-package :kmrcl)
 
 
-(defun mapappend (func seq)
-  (apply #'append (mapcar func seq)))
-
-(defun mapcar-append-string-nontailrec (func v)
-  "Concatenate results of mapcar lambda calls"  
-  (aif (car v)
-       (concatenate 'string (funcall func it)
-                   (mapcar-append-string-nontailrec func (cdr v)))
-       ""))
-
-
-(defun mapcar-append-string (func v &optional (accum ""))
-  "Concatenate results of mapcar lambda calls"  
-  (aif (car v)
-       (mapcar-append-string 
-       func 
-       (cdr v) 
-       (concatenate 'string accum (funcall func it)))
-       accum))
-
-(defun mapcar2-append-string-nontailrec (func la lb)
-  "Concatenate results of mapcar lambda call's over two lists"  
-  (let ((a (car la))
-       (b (car lb)))
-    (if (and a b)
-      (concatenate 'string (funcall func a b)
-                  (mapcar2-append-string-nontailrec func (cdr la) (cdr lb)))
-      "")))
-  
-(defun mapcar2-append-string (func la lb &optional (accum ""))
-  "Concatenate results of mapcar lambda call's over two lists"  
-  (let ((a (car la))
-       (b (car lb)))
-    (if (and a b)
-       (mapcar2-append-string 
-        func 
-        (cdr la) 
-        (cdr lb)
-        (concatenate 'string accum (funcall func a b)))
-      accum)))
-
-
 (defun nsubseq (sequence start &optional end)
   "Return a subsequence by pointing to location in original sequence"
   (unless end (setq end (length sequence)))
index af477bba105de8d2784fd0df16e9a7e63d51d0d0..a9acdc27281ad98ef62d1d963d569f0e55fb20a0 100644 (file)
@@ -7,7 +7,7 @@
 ;;;; Programmer:    Kevin M. Rosenberg
 ;;;; Date Started:  Apr 2000
 ;;;;
-;;;; $Id: strings.lisp,v 1.20 2003/05/05 21:49:48 kevin Exp $
+;;;; $Id: strings.lisp,v 1.21 2003/05/06 01:43:14 kevin Exp $
 ;;;;
 ;;;; This file, part of KMRCL, is Copyright (c) 2002 by Kevin M. Rosenberg
 ;;;;
@@ -233,3 +233,20 @@ list of characters and replacement strings."
       (setf (aref vec i) (char-code (schar str i))))
     vec))
 
+(defun concat-separated-strings (separator &rest lists)
+  (format nil (format nil "~~{~~A~~^~A~~}" separator) (append-sublists lists)))
+
+(defun print-separated-strings (strm separator &rest lists)
+  (declare (optimize (speed 3) (safety 0) (space 0) (debug 0)
+                    (compilation-speed 0)))
+  (do* ((rest-lists lists (cdr rest-lists))
+       (list (car rest-lists) (car rest-lists))
+       (last-list (null (cdr rest-lists)) (null (cdr rest-lists))))
+       ((null list) strm)
+    (do* ((lst list (cdr lst))
+         (elem (car lst) (car lst))
+         (last-elem (null (cdr lst)) (null (cdr lst))))
+        ((null lst))
+      (write-string elem strm)
+      (unless (and last-elem last-list)
+       (write-string separator strm)))))
index fc3da0d203c7d1723ab4a5a2acea1f7c091a0fd8..6e4e64d74412ddffc7480505a9cc8e9342c72898 100644 (file)
@@ -7,7 +7,7 @@
 ;;;; Author:        Kevin M. Rosenberg
 ;;;; Date Started:  Apr 2003
 ;;;;
-;;;; $Id: tests.lisp,v 1.8 2003/05/05 21:36:50 kevin Exp $
+;;;; $Id: tests.lisp,v 1.9 2003/05/06 01:43:14 kevin Exp $
 ;;;;
 ;;;; This file is Copyright (c) 2000-2002 by Kevin M. Rosenberg
 ;;;;
 (deftest str.23 (delimited-string-to-list "ab" #\space t) ("ab"))
 (deftest str.24 (delimited-string-to-list "ab|" #\|) ("ab" ""))
 (deftest str.25 (delimited-string-to-list "ab|" #\| t) ("ab"))
-  
+
+(deftest ap1.1 (append1 '((a b) (c d)) (a b c d)))
+(deftest ap1.2 (append1 nil) nil)
+(deftest ap1.3 (append1 '((a b))) (a b))
+(deftest ap1.4 (append1 '((a))) (a))
+(deftest ap1.5 (append1 '((a) (b) (c d (e f g)))) (a b c d (e f g)))
+
 (eval-when (:compile-toplevel :load-toplevel :execute)
   (when (find-package '#:kmr-mop)
     (pushnew :kmrtest-mop cl:*features*)))