~ chicken-core (chicken-5) 3e3ccd8dee517985cf84e4843ddd94d87fb55e7e


commit 3e3ccd8dee517985cf84e4843ddd94d87fb55e7e
Author:     Peter Bex <peter@more-magic.net>
AuthorDate: Sat Nov 5 20:41:07 2016 +0100
Commit:     Evan Hanson <evhan@foldling.org>
CommitDate: Sun Nov 6 10:54:22 2016 +1300

    Use "portable" keyword style when WRITEing.
    
    This ensures s-expressions are readable.  The selected keyword style of
    the program that eventually reads it doesn't need to match the keyword
    of the program that writes it.
    
    Signed-off-by: Evan Hanson <evhan@foldling.org>

diff --git a/NEWS b/NEWS
index 7f0975cb..3d785825 100644
--- a/NEWS
+++ b/NEWS
@@ -43,6 +43,8 @@
     added for testing whether a port is open in a specific direction.
   - An `include-relative` form has been added to the chicken module.
     This works like `load-relative` but for textual inclusion.
+  - Keywords are now always written in "portable" style by WRITE, so
+    that the reader's keyword style doesn't need to match the writer's.
 
 - Module system
   - The compiler has been modularised, for improved namespacing.  This
diff --git a/library.scm b/library.scm
index 0ec0a57e..90beb8c8 100644
--- a/library.scm
+++ b/library.scm
@@ -4040,7 +4040,8 @@ EOF
 		((##core#inline "C_forwardedp" x) (outstr port "#<invalid forwarded object>"))
 		((##core#inline "C_symbolp" x)
 		 (cond ((fx= 0 (##sys#byte (##sys#slot x 1) 0)) ; keyword
-			(case ksp
+			;; Force portable #: style for readable output
+			(case (and (not readable) ksp)
 			  ((#:prefix)
 			   (outchr port #\:)
 			   (outsym port x))
diff --git a/tests/library-tests.scm b/tests/library-tests.scm
index ac09485b..b928653a 100644
--- a/tests/library-tests.scm
+++ b/tests/library-tests.scm
@@ -341,7 +341,7 @@
     (assert (string=? "foo bar" (symbol->string kw)))
     (assert (string=? "foo bar:"
 		      (with-output-to-string (lambda () (display kw)))))
-    (assert (string=? "|foo bar|:"
+    (assert (string=? "#:|foo bar|"
 		      (with-output-to-string (lambda () (write kw)))))))
 
 (parameterize ((keyword-style #:prefix))
@@ -352,7 +352,7 @@
     (assert (string=? "foo bar" (symbol->string kw)))
     (assert (string=? ":foo bar"
 		      (with-output-to-string (lambda () (display kw)))))
-    (assert (string=? ":|foo bar|"
+    (assert (string=? "#:|foo bar|"
 		      (with-output-to-string (lambda () (write kw)))))))
 
 (assert (eq? '|#:| (string->symbol "#:")))
Trap