mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-07-12 15:37:35 +02:00
try-fitted2/output* calls output on the argument string if it's
determined the string will not exceed the column width. But output is the caller environment's output state variable. A better choice is output-default. In two places (length+ form) is replaced with (or (length+ form) +inf.0) so that arithmetic can be performed on the result. To support cyclic structures in pretty-simply (wrapped with trimmed/lazy), the call-with-output form in pp-with-indent needs to be wrapped with an appropriate trimmed/lazy. In pp-pair, call (pp (car ls)) instead of (pretty (car ls)). In pretty-simply, don't use call-with-output, that prevents (trimmed/lazy n (pretty-simply ...)) from working at all on cyclic input.
This commit is contained in:
parent
b947e4ef47
commit
406aacf4dd
1 changed files with 11 additions and 11 deletions
|
@ -63,7 +63,7 @@
|
|||
((> col width)
|
||||
(abort fail))
|
||||
(else
|
||||
(output str)))))))))
|
||||
(output-default str)))))))))
|
||||
(fn-fork
|
||||
(with ((output output*)
|
||||
(port out))
|
||||
|
@ -151,7 +151,7 @@
|
|||
=> cdr)
|
||||
(else #f))))
|
||||
(if (and (number? indent) (negative? indent))
|
||||
(max 0 (- (+ (length+ form) indent) 1))
|
||||
(max 0 (- (+ (or (length+ form) +inf.0) indent) 1))
|
||||
indent)))
|
||||
|
||||
(define (with-reset-shares shares proc)
|
||||
|
@ -182,9 +182,11 @@
|
|||
;; reset in case we don't fit on the first line
|
||||
(reset-shares (with-reset-shares shares nothing)))
|
||||
(call-with-output
|
||||
(each " "
|
||||
(joined/shares
|
||||
(lambda (x) (pp-flat x pp shares)) fixed shares " "))
|
||||
(trimmed/lazy (- width col2)
|
||||
(each " "
|
||||
(joined/shares
|
||||
(lambda (x) (pp-flat x pp shares)) fixed shares " "))
|
||||
)
|
||||
(lambda (first-line)
|
||||
(cond
|
||||
((< (+ col2 (string-width first-line)) width)
|
||||
|
@ -195,7 +197,7 @@
|
|||
(cond
|
||||
((not (or (null? tail) (pair? tail)))
|
||||
(each ". " (pp tail pp shares)))
|
||||
((> (length+ (cdr ls)) (or indent-rule 1))
|
||||
((> (or (length+ (cdr ls)) +inf.0) (or indent-rule 1))
|
||||
(each sep (joined/shares pp tail shares sep)))
|
||||
(else
|
||||
nothing)))))
|
||||
|
@ -299,7 +301,7 @@
|
|||
(cond
|
||||
;; one element list, no lines to break
|
||||
((null? (cdr ls))
|
||||
(each "(" (pretty (car ls)) ")"))
|
||||
(each "(" (pp (car ls)) ")"))
|
||||
;; quote or other abbrev
|
||||
((and (pair? (cdr ls)) (null? (cddr ls))
|
||||
(assq (car ls) syntax-abbrevs))
|
||||
|
@ -362,7 +364,5 @@
|
|||
|
||||
(define (pretty-simply obj)
|
||||
(fn ()
|
||||
(call-with-output
|
||||
(each (pp obj (extract-shared-objects #f #f))
|
||||
fl)
|
||||
displayed)))
|
||||
(each (pp obj (extract-shared-objects #f #f))
|
||||
fl)))
|
||||
|
|
Loading…
Add table
Reference in a new issue