>From fe97ba69a041c34c2d98a24baca03617f26c1df4 Mon Sep 17 00:00:00 2001 From: Peter Bex Date: Sun, 26 May 2013 19:38:17 +0200 Subject: [PATCH 1/2] Added #\null and #\escape character literal names, for R7RS compatibility. WRITE now uses this instead of the old #\nul and #\esc, so other impls can READ s-expression written by CHICKEN. Unfortunately, the flip side is that older CHICKENs can't READ data written by newer CHICKENs. --- NEWS | 2 ++ library.scm | 4 ++++ tests/r7rs-tests.scm | 23 +++++++++++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/NEWS b/NEWS index 07a8a5a..f2d28fc 100644 --- a/NEWS +++ b/NEWS @@ -22,6 +22,8 @@ and "#!rest" in type-declarations (suggested by Joerg Wittenberger). - Vectors, SRFI-4 number vectors and blobs are now self-evaluating for R7RS compatibility. Being literal constants, they are implicitly quoted. + - For R7RS compatibility, named character literals #\escape and #\null are + supported as aliases for #\esc and #\nul. WRITE will output R7RS names. - Compiler - the "inline" declaration does not force inlining anymore as recursive diff --git a/library.scm b/library.scm index f42ddd7..cd33b09 100644 --- a/library.scm +++ b/library.scm @@ -1527,6 +1527,8 @@ EOF (and-let* ([a (assq x names-to-chars)]) (##sys#slot a 1) ) ] ) ) ) ) ) +;; TODO: Use the character names here in the next release? Or just +;; use the numbers everywhere, for clarity? (char-name 'space #\space) (char-name 'tab #\tab) (char-name 'linefeed #\linefeed) @@ -1534,8 +1536,10 @@ EOF (char-name 'vtab (integer->char 11)) (char-name 'delete (integer->char 127)) (char-name 'esc (integer->char 27)) +(char-name 'escape (integer->char 27)) (char-name 'alarm (integer->char 7)) (char-name 'nul (integer->char 0)) +(char-name 'null (integer->char 0)) (char-name 'return #\return) (char-name 'page (integer->char 12)) (char-name 'backspace (integer->char 8)) diff --git a/tests/r7rs-tests.scm b/tests/r7rs-tests.scm index bc21294..368f9f4 100644 --- a/tests/r7rs-tests.scm +++ b/tests/r7rs-tests.scm @@ -71,6 +71,29 @@ +(SECTION 6 6) + + +(define (integer->named-char x) + (with-output-to-string (lambda () (write (integer->char x))))) + +(test "#\\alarm" integer->named-char #x07) +(test "#\\backspace" integer->named-char #x08) +(test "#\\delete" integer->named-char #x7f) +(test "#\\escape" integer->named-char #x1b) +(test "#\\newline" integer->named-char #x0a) +(test "#\\null" integer->named-char #x00) +(test "#\\return" integer->named-char #x0d) +(test "#\\space" integer->named-char #x20) +(test "#\\tab" integer->named-char #x09) + + + +;; NOT YET (is ambiguous with existing \xNN syntax in Chicken) +#;(test #\tab escaped-char "x9;") +#;(test #\tab escaped-char "x09;") + + (SECTION 6 8) ;; Symbols are implicitly quoted inside self-evaluating vectors. -- 1.8.2.3