From e90bb0c956979855b9ec2a3902e9638dbd026881 Mon Sep 17 00:00:00 2001 From: Peter Bex Date: Sat, 5 Nov 2016 20:41:07 +0100 Subject: [PATCH 2/2] 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. --- NEWS | 2 ++ library.scm | 3 ++- tests/library-tests.scm | 4 ++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/NEWS b/NEWS index 7f0975c..3d78582 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 3c94488..aa00b47 100644 --- a/library.scm +++ b/library.scm @@ -4040,7 +4040,8 @@ EOF ((##core#inline "C_forwardedp" x) (outstr port "#")) ((##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 ac09485..b928653 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 "#:"))) -- 2.1.4