mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-12 06:41:13 +02:00
format.scm cleanups
* module/ice-9/format.scm (format:symbol-case-conv) (format:iobj-case-conv): Remove these exports, they were not used. (format:expch): Remove this one, though it was used. (format:floats, format:complex-numbers, format:radix-pref): Inline these "configuration variables" into the format body.
This commit is contained in:
parent
e3e3394374
commit
9ebf1af3c1
1 changed files with 16 additions and 60 deletions
|
@ -32,35 +32,10 @@
|
||||||
(define-module (ice-9 format)
|
(define-module (ice-9 format)
|
||||||
#:use-module (ice-9 and-let-star)
|
#:use-module (ice-9 and-let-star)
|
||||||
#:autoload (ice-9 pretty-print) (pretty-print truncated-print)
|
#:autoload (ice-9 pretty-print) (pretty-print truncated-print)
|
||||||
#:replace (format)
|
#:replace (format))
|
||||||
#:export (format:symbol-case-conv
|
|
||||||
format:iobj-case-conv
|
|
||||||
format:expch))
|
|
||||||
|
|
||||||
;;; Configuration ------------------------------------------------------------
|
;;; Configuration ------------------------------------------------------------
|
||||||
|
|
||||||
(define format:symbol-case-conv #f)
|
|
||||||
;; Symbols are converted by symbol->string so the case of the printed
|
|
||||||
;; symbols is implementation dependent. format:symbol-case-conv is a
|
|
||||||
;; one arg closure which is either #f (no conversion), string-upcase!,
|
|
||||||
;; string-downcase! or string-capitalize!.
|
|
||||||
|
|
||||||
(define format:iobj-case-conv #f)
|
|
||||||
;; As format:symbol-case-conv but applies for the representation of
|
|
||||||
;; implementation internal objects.
|
|
||||||
|
|
||||||
(define format:expch #\E)
|
|
||||||
;; The character prefixing the exponent value in ~e printing.
|
|
||||||
|
|
||||||
(define format:floats (provided? 'inexact))
|
|
||||||
;; Detects if the scheme system implements flonums (see at eof).
|
|
||||||
|
|
||||||
(define format:complex-numbers (provided? 'complex))
|
|
||||||
;; Detects if the scheme system implements complex numbers.
|
|
||||||
|
|
||||||
(define format:radix-pref (char=? #\# (string-ref (number->string 8 8) 0)))
|
|
||||||
;; Detects if number->string adds a radix prefix.
|
|
||||||
|
|
||||||
(define format:ascii-non-printable-charnames
|
(define format:ascii-non-printable-charnames
|
||||||
'#("nul" "soh" "stx" "etx" "eot" "enq" "ack" "bel"
|
'#("nul" "soh" "stx" "etx" "eot" "enq" "ack" "bel"
|
||||||
"bs" "ht" "nl" "vt" "np" "cr" "so" "si"
|
"bs" "ht" "nl" "vt" "np" "cr" "so" "si"
|
||||||
|
@ -385,30 +360,19 @@
|
||||||
(format:out-num-padded ; any Radix
|
(format:out-num-padded ; any Radix
|
||||||
modifier (next-arg) (cdr params) (car params)))
|
modifier (next-arg) (cdr params) (car params)))
|
||||||
(anychar-dispatch))
|
(anychar-dispatch))
|
||||||
((#\F) ; Fixed-format floating-point
|
((#\F) ; Fixed-format floating-point
|
||||||
(if format:floats
|
(format:out-fixed modifier (next-arg) params)
|
||||||
(format:out-fixed modifier (next-arg) params)
|
(anychar-dispatch))
|
||||||
(format:out-str (number->string (next-arg))))
|
((#\E) ; Exponential floating-point
|
||||||
(anychar-dispatch))
|
(format:out-expon modifier (next-arg) params)
|
||||||
((#\E) ; Exponential floating-point
|
(anychar-dispatch))
|
||||||
(if format:floats
|
((#\G) ; General floating-point
|
||||||
(format:out-expon modifier (next-arg) params)
|
(format:out-general modifier (next-arg) params)
|
||||||
(format:out-str (number->string (next-arg))))
|
(anychar-dispatch))
|
||||||
(anychar-dispatch))
|
((#\$) ; Dollars floating-point
|
||||||
((#\G) ; General floating-point
|
(format:out-dollar modifier (next-arg) params)
|
||||||
(if format:floats
|
(anychar-dispatch))
|
||||||
(format:out-general modifier (next-arg) params)
|
|
||||||
(format:out-str (number->string (next-arg))))
|
|
||||||
(anychar-dispatch))
|
|
||||||
((#\$) ; Dollars floating-point
|
|
||||||
(if format:floats
|
|
||||||
(format:out-dollar modifier (next-arg) params)
|
|
||||||
(format:out-str (number->string (next-arg))))
|
|
||||||
(anychar-dispatch))
|
|
||||||
((#\I) ; Complex numbers
|
((#\I) ; Complex numbers
|
||||||
(if (not format:complex-numbers)
|
|
||||||
(format:error
|
|
||||||
"complex numbers not supported by this scheme system"))
|
|
||||||
(let ((z (next-arg)))
|
(let ((z (next-arg)))
|
||||||
(if (not (complex? z))
|
(if (not (complex? z))
|
||||||
(format:error "argument not a complex number"))
|
(format:error "argument not a complex number"))
|
||||||
|
@ -440,10 +404,7 @@
|
||||||
((>= c #x7f)
|
((>= c #x7f)
|
||||||
(format:out-str "#\\")
|
(format:out-str "#\\")
|
||||||
(format:out-str
|
(format:out-str
|
||||||
(if format:radix-pref
|
(number->string c 8)))
|
||||||
(let ((s (number->string c 8)))
|
|
||||||
(substring s 2 (string-length s)))
|
|
||||||
(number->string c 8))))
|
|
||||||
(else
|
(else
|
||||||
(format:out-char ch)))))
|
(format:out-char ch)))))
|
||||||
(else (format:out-char ch))))
|
(else (format:out-char ch))))
|
||||||
|
@ -887,10 +848,7 @@
|
||||||
(vector-ref format:ascii-non-printable-charnames int-rep))
|
(vector-ref format:ascii-non-printable-charnames int-rep))
|
||||||
((= int-rep 127) "del")
|
((= int-rep 127) "del")
|
||||||
((>= int-rep 128) ; octal representation
|
((>= int-rep 128) ; octal representation
|
||||||
(if format:radix-pref
|
(number->string int-rep 8))
|
||||||
(let ((s (number->string int-rep 8)))
|
|
||||||
(substring s 2 (string-length s)))
|
|
||||||
(number->string int-rep 8)))
|
|
||||||
(else (string ch)))))))
|
(else (string ch)))))))
|
||||||
|
|
||||||
(format:space-ch (char->integer #\space))
|
(format:space-ch (char->integer #\space))
|
||||||
|
@ -934,8 +892,6 @@
|
||||||
(lambda (modifier number pars radix)
|
(lambda (modifier number pars radix)
|
||||||
(if (not (integer? number)) (format:error "argument not an integer"))
|
(if (not (integer? number)) (format:error "argument not an integer"))
|
||||||
(let ((numstr (number->string number radix)))
|
(let ((numstr (number->string number radix)))
|
||||||
(if (and format:radix-pref (not (= radix 10)))
|
|
||||||
(set! numstr (substring numstr 2 (string-length numstr))))
|
|
||||||
(if (and (null? pars) (not modifier))
|
(if (and (null? pars) (not modifier))
|
||||||
(format:out-str numstr)
|
(format:out-str numstr)
|
||||||
(let ((l (length pars))
|
(let ((l (length pars))
|
||||||
|
@ -1676,7 +1632,7 @@
|
||||||
|
|
||||||
(format:en-out
|
(format:en-out
|
||||||
(lambda (edigits expch)
|
(lambda (edigits expch)
|
||||||
(format:out-char (if expch (integer->char expch) format:expch))
|
(format:out-char (if expch (integer->char expch) #\E))
|
||||||
(format:out-char (if format:en-pos? #\+ #\-))
|
(format:out-char (if format:en-pos? #\+ #\-))
|
||||||
(if edigits
|
(if edigits
|
||||||
(if (< format:en-len edigits)
|
(if (< format:en-len edigits)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue