mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-05-20 14:19:18 +02:00
Using brace-notation for write/ss for records not containing any shares.
This commit is contained in:
parent
a56b497a00
commit
befe63d6ba
1 changed files with 47 additions and 51 deletions
|
@ -55,58 +55,54 @@
|
|||
(set-cdr! cell count)
|
||||
(set! count (+ count 1))))
|
||||
(cont x cell)))))
|
||||
(cond
|
||||
((null? shared)
|
||||
(write x out))
|
||||
(else
|
||||
(let wr ((x x))
|
||||
(check-shared
|
||||
x
|
||||
""
|
||||
(lambda (x shared?)
|
||||
(cond
|
||||
((pair? x)
|
||||
(display "(" out)
|
||||
(wr (car x))
|
||||
(let lp ((ls (cdr x)))
|
||||
(check-shared
|
||||
ls
|
||||
" . "
|
||||
(lambda (ls shared?)
|
||||
(cond ((null? ls))
|
||||
((pair? ls)
|
||||
(cond
|
||||
(shared?
|
||||
(display "(" out)
|
||||
(wr (car ls))
|
||||
(check-shared
|
||||
(cdr ls)
|
||||
" . "
|
||||
(lambda (ls shared?) (lp ls)))
|
||||
(display ")" out))
|
||||
(else
|
||||
(display " " out)
|
||||
(wr (car ls))
|
||||
(lp (cdr ls)))))
|
||||
(let wr ((x x))
|
||||
(check-shared
|
||||
x
|
||||
""
|
||||
(lambda (x shared?)
|
||||
(cond
|
||||
((pair? x)
|
||||
(display "(" out)
|
||||
(wr (car x))
|
||||
(let lp ((ls (cdr x)))
|
||||
(check-shared
|
||||
ls
|
||||
" . "
|
||||
(lambda (ls shared?)
|
||||
(cond ((null? ls))
|
||||
((pair? ls)
|
||||
(cond
|
||||
(shared?
|
||||
(display "(" out)
|
||||
(wr (car ls))
|
||||
(check-shared
|
||||
(cdr ls)
|
||||
" . "
|
||||
(lambda (ls shared?) (lp ls)))
|
||||
(display ")" out))
|
||||
(else
|
||||
(display " . " out)
|
||||
(wr ls))))))
|
||||
(display ")" out))
|
||||
((vector? x)
|
||||
(display "#(" out)
|
||||
(let ((len (vector-length x)))
|
||||
(cond ((> len 0)
|
||||
(wr (vector-ref x 0))
|
||||
(do ((i 1 (+ i 1)))
|
||||
((= i len))
|
||||
(display " " out)
|
||||
(wr (vector-ref x i))))))
|
||||
(display ")" out))
|
||||
((let ((type (type-of x)))
|
||||
(and (type? type) (type-printer type)))
|
||||
=> (lambda (printer) (printer x wr out)))
|
||||
(else
|
||||
(write x out))))))))))
|
||||
(display " " out)
|
||||
(wr (car ls))
|
||||
(lp (cdr ls)))))
|
||||
(else
|
||||
(display " . " out)
|
||||
(wr ls))))))
|
||||
(display ")" out))
|
||||
((vector? x)
|
||||
(display "#(" out)
|
||||
(let ((len (vector-length x)))
|
||||
(cond ((> len 0)
|
||||
(wr (vector-ref x 0))
|
||||
(do ((i 1 (+ i 1)))
|
||||
((= i len))
|
||||
(display " " out)
|
||||
(wr (vector-ref x i))))))
|
||||
(display ")" out))
|
||||
((let ((type (type-of x)))
|
||||
(and (type? type) (type-printer type)))
|
||||
=> (lambda (printer) (printer x wr out)))
|
||||
(else
|
||||
(write x out))))))))
|
||||
|
||||
(define write/ss write-with-shared-structure)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue