From ca0dcaef675ae959bb83754254fb68cb5f0ec670 Mon Sep 17 00:00:00 2001 From: "Kevin M. Rosenberg" Date: Tue, 6 May 2003 01:43:14 +0000 Subject: [PATCH] r4822: *** empty log message *** --- buff-input.lisp | 5 +++-- lists.lisp | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- package.lisp | 5 ++++- seqs.lisp | 44 +------------------------------------------- strings.lisp | 19 ++++++++++++++++++- tests.lisp | 10 ++++++++-- 6 files changed, 82 insertions(+), 50 deletions(-) diff --git a/buff-input.lisp b/buff-input.lisp index f0802bc..d17590d 100644 --- a/buff-input.lisp +++ b/buff-input.lisp @@ -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)) diff --git a/lists.lisp b/lists.lisp index ef13453..a7ae3d1 100644 --- a/lists.lisp +++ b/lists.lisp @@ -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 ;;;; @@ -88,4 +88,51 @@ :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)) diff --git a/package.lisp b/package.lisp index a2d3e28..5a705ca 100644 --- a/package.lisp +++ b/package.lisp @@ -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 diff --git a/seqs.lisp b/seqs.lisp index b2a7508..2e261bd 100644 --- 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 ;;;; @@ -19,48 +19,6 @@ (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))) diff --git a/strings.lisp b/strings.lisp index af477bb..a9acdc2 100644 --- a/strings.lisp +++ b/strings.lisp @@ -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))))) diff --git a/tests.lisp b/tests.lisp index fc3da0d..6e4e64d 100644 --- a/tests.lisp +++ b/tests.lisp @@ -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 ;;;; @@ -55,7 +55,13 @@ (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*))) -- 2.34.1