From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Matthias Koeppe Newsgroups: gmane.lisp.guile.devel Subject: Patch for ice-9/pretty-print.scm Date: Wed, 26 May 2004 17:30:17 +0200 Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Message-ID: NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1085592215 18742 80.91.224.253 (26 May 2004 17:23:35 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 26 May 2004 17:23:35 +0000 (UTC) Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Wed May 26 19:23:15 2004 Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1BT27X-0002Yv-00 for ; Wed, 26 May 2004 19:23:15 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.34) id 1BT1md-00024x-9t for guile-devel@m.gmane.org; Wed, 26 May 2004 13:01:39 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.34) id 1BT1lL-0001ux-5C for guile-devel@gnu.org; Wed, 26 May 2004 13:00:19 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.34) id 1BT1ko-0001rj-Bo for guile-devel@gnu.org; Wed, 26 May 2004 13:00:17 -0400 Original-Received: from [141.44.75.40] (helo=merkur.math.uni-magdeburg.de) by monty-python.gnu.org with esmtp (Exim 4.34) id 1BT0MK-0003c1-Rc for guile-devel@gnu.org; Wed, 26 May 2004 11:30:25 -0400 Original-Received: from beta ([141.44.75.78] helo=beta.math.uni-magdeburg.de) by merkur.math.uni-magdeburg.de with esmtp (Exim 4.10) id 1BT0MF-00064D-00 for guile-devel@gnu.org; Wed, 26 May 2004 17:30:19 +0200 Original-Received: (from mkoeppe@localhost) by beta.math.uni-magdeburg.de (8.11.7+Sun/8.11.7) id i4QFUHc29970; Wed, 26 May 2004 17:30:17 +0200 (MEST) X-Authentication-Warning: beta.math.uni-magdeburg.de: mkoeppe set sender to mkoeppe@mail.math.uni-magdeburg.de using -f Original-To: guile-devel@gnu.org X-Warning: no 'abuse'-account in domain mail.math.uni-magdeburg.de (cf. RFC2142/4.) X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.4 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: main.gmane.org gmane.lisp.guile.devel:3759 X-Report-Spam: http://spam.gmane.org/gmane.lisp.guile.devel:3759 Here is a patch for CVS Guile that removes a restriction from the pretty-print procedure, as well as 40 lines of code implementing the restriction and 19 lines of its documentation. 2004-05-26 Matthias Koeppe * pretty-print.scm (generic-write): In the local procedure `wr', use object->string to print all data (except for the reader macros), rather than implementing an own printer. The user-visible difference is that procedures and control characters like #\tab are now printed in the same way as by `write'. Index: ice-9/pretty-print.scm =================================================================== RCS file: /cvsroot/guile/guile/guile-core/ice-9/pretty-print.scm,v retrieving revision 1.7 diff -u -p -r1.7 pretty-print.scm --- ice-9/pretty-print.scm 5 Apr 2003 19:04:27 -0000 1.7 +++ ice-9/pretty-print.scm 26 May 2004 15:18:51 -0000 @@ -1,6 +1,6 @@ ;;;; -*-scheme-*- ;;;; -;;;; Copyright (C) 2001 Free Software Foundation, Inc. +;;;; Copyright (C) 2001, 2004 Free Software Foundation, Inc. ;;;; ;;;; This library is free software; you can redistribute it and/or ;;;; modify it under the terms of the GNU Lesser General Public @@ -53,53 +53,12 @@ (and col (output str) (+ col (string-length str)))) (define (wr obj col) - - (define (wr-expr expr col) - (if (read-macro? expr) - (wr (read-macro-body expr) (out (read-macro-prefix expr) col)) - (wr-lst expr col))) - - (define (wr-lst l col) - (if (pair? l) - (let loop ((l (cdr l)) - (col (and col (wr (car l) (out "(" col))))) - (cond ((not col) col) - ((pair? l) - (loop (cdr l) (wr (car l) (out " " col)))) - ((null? l) (out ")" col)) - (else (out ")" (wr l (out " . " col)))))) - (out "()" col))) - - (cond ((pair? obj) (wr-expr obj col)) - ((null? obj) (wr-lst obj col)) - ((vector? obj) (wr-lst (vector->list obj) (out "#" col))) - ((boolean? obj) (out (if obj "#t" "#f") col)) - ((number? obj) (out (number->string obj) col)) - ((symbol? obj) (out (symbol->string obj) col)) - ((procedure? obj) (out "#[procedure]" col)) - ((string? obj) (if display? - (out obj col) - (let loop ((i 0) (j 0) (col (out "\"" col))) - (if (and col (< j (string-length obj))) - (let ((c (string-ref obj j))) - (if (or (char=? c #\\) - (char=? c #\")) - (loop j - (+ j 1) - (out "\\" - (out (substring obj i j) - col))) - (loop i (+ j 1) col))) - (out "\"" - (out (substring obj i j) col)))))) - ((char? obj) (if display? - (out (make-string 1 obj) col) - (out (case obj - ((#\space) "space") - ((#\newline) "newline") - (else (make-string 1 obj))) - (out "#\\" col)))) - (else (out (object->string obj) col)))) + (cond ((and (pair? obj) + (read-macro? obj)) + (wr (read-macro-body obj) + (out (read-macro-prefix obj) col))) + (else + (out (object->string obj (if display? display write)) col)))) (define (pp obj col) Index: doc/ref/misc-modules.texi =================================================================== RCS file: /cvsroot/guile/guile/guile-core/doc/ref/misc-modules.texi,v retrieving revision 1.10 diff -u -p -r1.10 misc-modules.texi --- doc/ref/misc-modules.texi 21 Apr 2004 14:32:26 -0000 1.10 +++ doc/ref/misc-modules.texi 26 May 2004 15:18:51 -0000 @@ -59,25 +59,6 @@ Print within the given @var{columns}. T @end table @end deffn -Beware: Since @code{pretty-print} uses it's own write procedure, it's -output will not be the same as for example the output of @code{write}. -Consider the following example. - -@lisp -(write (lambda (x) x)) -@print{} -# - -(pretty-print (lambda (x) x)) -@print{} -#[procedure] -@end lisp - -The reason is that @code{pretty-print} does not know as much about -Guile's object types as the builtin procedures. This is particularly -important for smobs, for which a write procedure can be defined and be -used by @code{write}, but not by @code{pretty-print}. - @page @node Formatted Output -- Matthias Koeppe -- http://www.math.uni-magdeburg.de/~mkoeppe _______________________________________________ Guile-devel mailing list Guile-devel@gnu.org http://mail.gnu.org/mailman/listinfo/guile-devel