use define-record-writer to set custom writer to <array> type

This commit is contained in:
Yuichi Nishiwaki 2014-08-07 11:52:00 +09:00
parent 75138db4db
commit fff22f253f
1 changed files with 10 additions and 12 deletions

View File

@ -89,19 +89,17 @@
(define (array-for-each proc ary)
(for-each proc (array->list ary)))
(define (print-array array)
(define-record-writer (<array> array)
(call-with-port (open-output-string)
(lambda (port)
(display "#.(array" port)
(array-for-each
(lambda (obj)
(display " " port)
(write obj port))
array)
(display ")" port)
(get-output-string port))))
(record-set! <array> 'writer print-array)
(lambda (port)
(display "#.(array" port)
(array-for-each
(lambda (obj)
(display " " port)
(write obj port))
array)
(display ")" port)
(get-output-string port))))
(export make-array
array