;;;; 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
;;;;
(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))
;;;; 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))
;;;; 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
;;;;
#:delimited-string-to-list
#:list-to-delimited-string
#:flatten
+ #:append-sublists
#:indent-spaces
#:print-list
#:print-rows
#:substitute-chars-strings
#:add-sql-quotes
#:escape-backslashes
+ #:concat-separated-strings
+ #:print-separated-strings
;; symbols.lisp
#:ensure-keyword
;;;; 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)))
;;;; 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
;;;;
(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)))))
;;;; 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*)))