(define-method ->string () self) (define-method ->string () (symbol->string self)) (define-method ->string () (long->string self)) (define-method ->string () (double->string self)) (define-structure (buffer column)) (define-function port options (new (car options) 0)) (define-function string-port () (new (array) 0)) (define-function console-port () (new () 0)) (define-method do-print () (print "")) (define-function port-contents (p) (let ((buf (-buffer p))) (and buf (array->string buf)))) (define-method port-put (char) (if self.buffer (array-append self.buffer char) (print (format "%lc" char))) (set self.column (if (or (= char ?\n) (= char ?\r)) 0 (+ self.column 1))) char) (define-method port-write-seq (seq) (for-each (->string seq) (lambda (x) (port-put self x)))) (define-method port-write seqs (list-do seq seqs (port-write-seq self seq))) (define-method port-newline () (and (> self.column 0) (port-put self ?\n))) (define-method port-indent (col) (for (i 0 col) (port-put self ? ))) (define-method port-newline-indent (col) (port-newline self) (port-indent self col))