Skip to content
Browse files

* Implemented FORMAT-TEXTUAL-LIST.

  • Loading branch information...
1 parent f88051d commit 60141844949f40db0268304f4b26616a43e0764d Alexey Dejneka committed Aug 3, 2002
Showing with 58 additions and 0 deletions.
  1. +58 −0 text-formatting.lisp
View
58 text-formatting.lisp
@@ -0,0 +1,58 @@
+;;; -*- Mode: Lisp; Package: CLIM-INTERNALS -*-
+
+;;; (c) copyright 2002 by Alexey Dejneka (adejneka@comail.ru)
+
+;;; This library is free software; you can redistribute it and/or
+;;; modify it under the terms of the GNU Library General Public
+;;; License as published by the Free Software Foundation; either
+;;; version 2 of the License, or (at your option) any later version.
+;;;
+;;; This library 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
+;;; Library General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU Library General Public
+;;; License along with this library; if not, write to the
+;;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+;;; Boston, MA 02111-1307 USA.
+
+;;; TODO:
+;;;
+;;; - INDENTING-OUTPUT
+;;;
+;;; - FILLING-OUTPUT
+
+(in-package :CLIM-INTERNALS)
+
+(defun format-textual-list (sequence printer
+ &key stream separator conjunction
+ suppress-separator-before-conjunction
+ suppress-space-after-conjunction)
+ "Outputs the SEQUENCE of items as a \"textual list\" into
+STREAM. PRINTER is a function of an item and a stream. Between each
+two items the string SEPARATOR is placed. If the string CONJUCTION is
+supplied, it is placed before the last item.
+
+SUPPRESS-SEPARATOR-BEFORE-CONJUNCTION and
+SUPPRESS-SPACE-AFTER-CONJUNCTION are non-standard."
+ (orf stream *standard-output*)
+ (orf separator ", ")
+ (let* ((length (length sequence))
+ (n-rest length))
+ (map-repeated-sequence nil 1
+ (lambda (item)
+ (funcall printer item stream)
+ (decf n-rest)
+ (cond ((> n-rest 1)
+ (princ separator stream))
+ ((= n-rest 1)
+ (if conjunction
+ (progn
+ (unless suppress-separator-before-conjunction
+ (princ separator stream))
+ (princ conjunction stream)
+ (unless suppress-space-after-conjunction
+ (princ #\space stream)))
+ (princ separator stream)))))
+ sequence)))

0 comments on commit 6014184

Please sign in to comment.
Something went wrong with that request. Please try again.