guile-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Guile-commits] GNU Guile branch, master, updated. release_1-9-13-29-g5b


From: Ludovic Courtès
Subject: [Guile-commits] GNU Guile branch, master, updated. release_1-9-13-29-g5bae880
Date: Fri, 05 Nov 2010 00:45:46 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU Guile".

http://git.savannah.gnu.org/cgit/guile.git/commit/?id=5bae880e26e4691894523f9f420f8ab02cd75f01

The branch, master has been updated
       via  5bae880e26e4691894523f9f420f8ab02cd75f01 (commit)
      from  e414bf2178bc2144d0bbe5948f8f858ad656e192 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 5bae880e26e4691894523f9f420f8ab02cd75f01
Author: Ludovic Courtès <address@hidden>
Date:   Fri Nov 5 01:34:08 2010 +0100

    Improve handling of read macros in `pretty-print'.
    
    * module/ice-9/pretty-print.scm (generic-write)[wr]: Handle read macros
      that appear in the middle of a list.
    
    * test-suite/tests/print.test (prints?): New macro.
      ("pretty-print"): New test prefix.

-----------------------------------------------------------------------

Summary of changes:
 module/ice-9/pretty-print.scm |   23 +++++++++++++++++------
 test-suite/tests/print.test   |   35 +++++++++++++++++++++++++++++++++++
 2 files changed, 52 insertions(+), 6 deletions(-)

diff --git a/module/ice-9/pretty-print.scm b/module/ice-9/pretty-print.scm
index d3e3eca..8e67145 100644
--- a/module/ice-9/pretty-print.scm
+++ b/module/ice-9/pretty-print.scm
@@ -17,6 +17,8 @@
 ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 
USA
 ;;;; 
 (define-module (ice-9 pretty-print)
+  #:use-module (ice-9 match)
+  #:use-module (srfi srfi-1)
   #:export (pretty-print
             truncated-print))
 
@@ -54,12 +56,21 @@
     (and col (output str) (+ col (string-length str))))
 
   (define (wr 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))))
+    (let loop ((obj obj)
+               (col col))
+      (match obj
+        (((or 'quote 'quasiquote 'unquote 'unquote-splicing) body)
+         (wr body (out (read-macro-prefix obj) col)))
+        ((head . (rest ...))
+         ;; A proper list: do our own list printing so as to catch read
+         ;; macros that appear in the middle of the list.
+         (let ((col (loop head (out "(" col))))
+           (out ")"
+                (fold (lambda (i col)
+                        (loop i (out " " col)))
+                      col rest))))
+        (_
+         (out (object->string obj (if display? display write)) col)))))
 
   (define (pp obj col)
 
diff --git a/test-suite/tests/print.test b/test-suite/tests/print.test
index f8c9edc..e60a40f 100644
--- a/test-suite/tests/print.test
+++ b/test-suite/tests/print.test
@@ -20,6 +20,41 @@
   #:use-module (ice-9 pretty-print)
   #:use-module (test-suite lib))
 
+(define-syntax prints?
+  ;; #t if EXP prints as RESULT.
+  (syntax-rules ()
+    ((_ exp result)
+     (string=? result
+               (with-output-to-string
+                 (lambda ()
+                   (pretty-print 'exp)))))))
+
+
+(with-test-prefix "pretty-print"
+
+  (pass-if "pair"
+    (prints? (a . b) "(a . b)\n"))
+
+  (pass-if "list"
+    (prints? (a b c) "(a b c)\n"))
+
+  (pass-if "dotted list"
+    (prints? (a b . c) "(a b . c)\n"))
+
+  (pass-if "quote"
+    (prints? 'foo "'foo\n"))
+
+  (pass-if "non-starting quote"
+    (prints? (foo 'bar) "(foo 'bar)\n"))
+
+  (pass-if "nested quote"
+    (prints? (''foo) "(''foo)\n"))
+
+  (pass-if "quasiquote & co."
+    (prints?  (define foo `(bar ,(+ 2 3)))
+             "(define foo `(bar ,(+ 2 3)))\n")))
+
+
 (with-test-prefix "truncated-print"
   (define exp '(a b #(c d e) f . g))
 


hooks/post-receive
-- 
GNU Guile



reply via email to

[Prev in Thread] Current Thread [Next in Thread]