From bd78ebeed724803d23b1653e7fcf526186c96efe Mon Sep 17 00:00:00 2001 From: Alex Shinn Date: Sun, 10 Mar 2019 14:50:44 +0800 Subject: [PATCH] updating sign-rule to respect finalized SRFI 159 --- lib/chibi/show-test.sld | 3 +++ lib/chibi/show/write.scm | 16 +++++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/chibi/show-test.sld b/lib/chibi/show-test.sld index dfbef984..8a98dc35 100644 --- a/lib/chibi/show-test.sld +++ b/lib/chibi/show-test.sld @@ -221,6 +221,9 @@ ;; sign (test "+1" (show #f (numeric 1 10 #f #t))) (test "+1" (show #f (with ((sign-rule #t)) (numeric 1)))) + (test "(1)" (show #f (with ((sign-rule '("(" . ")"))) (numeric -1)))) + (test "-1" (show #f (with ((sign-rule '("-" . ""))) (numeric -1)))) + (test "−1" (show #f (with ((sign-rule '("−" . ""))) (numeric -1)))) (test "-0.0" (show #f (with ((sign-rule #t)) (numeric -0.0)))) (test "+0.0" (show #f (with ((sign-rule #t)) (numeric +0.0)))) diff --git a/lib/chibi/show/write.scm b/lib/chibi/show/write.scm index 62e2e22c..646b4c7b 100644 --- a/lib/chibi/show/write.scm +++ b/lib/chibi/show/write.scm @@ -303,11 +303,17 @@ (define (wrap-sign n sign-rule) (cond ((negative?* n) - (if (char? sign-rule) - (string-append (string sign-rule) - (wrap-comma (- n)) - (string (char-mirror sign-rule))) - (string-append "-" (wrap-comma (- n))))) + (cond + ((char? sign-rule) + (string-append (string sign-rule) + (wrap-comma (- n)) + (string (char-mirror sign-rule)))) + ((pair? sign-rule) + (string-append (car sign-rule) + (wrap-comma (- n)) + (cdr sign-rule))) + (else + (string-append "-" (wrap-comma (- n)))))) ((eq? #t sign-rule) (string-append "+" (wrap-comma n))) (else