list-writer1.patch
diff --git a/ac.scm b/ac.scm index 791a4ca..d59a4b1 100644 --- a/ac.scm +++ b/ac.scm @@ -872,6 +872,33 @@ (current-output-port))) b)) +(define (print* f port x) + + (define (print x) + (cond ((pair? x) + (display "(" port) + (print (car x)) + (print-cdr (cdr x))) + (#t + (f x port)))) + + (define (print-cdr y) + (cond ((or (eq? y 'nil) (eq? y '())) + (display ")" port)) + ((pair? y) + (display " " port) + (print (car y)) + (print-cdr (cdr y))) + (#t + (display " . " port) + (print y) + (display ")" port)))) + + (print x)) + +(define (write* x port) (print* write port x)) +(define (display* x port) (print* display port x)) + (define explicit-flush #f) (define (printwith f args) @@ -879,12 +906,12 @@ (cadr args) (current-output-port)))) (when (pair? args) - (f (ac-denil (car args)) port)) + (f (car args) port)) (unless explicit-flush (flush-output port))) 'nil) -(xdef write (lambda args (printwith write args))) -(xdef disp (lambda args (printwith display args))) +(xdef write (lambda args (printwith write* args))) +(xdef disp (lambda args (printwith display* args))) ; sread = scheme read. eventually replace by writing read @@ -1077,7 +1104,7 @@ (if (eqv? expr ':a) 'done (let ((val (arc-eval expr))) - (write (ac-denil val)) + (write* val (current-output-port)) (namespace-set-variable-value! '_that val) (namespace-set-variable-value! '_thatexpr expr) (newline)
arc3 writes Arc lists by converting them to Scheme lists and printing them using the Scheme writer. By implementing a writer for Arc values we can build upon this patch to customize the output of Arc values.
By itself, this patch is supposed to produce the same output as Arc does. (If it doesn’t, that would be a bug).
wget http://ycombinator.com/arc/arc3.tar tar xf arc3.tar cd arc3 wget -O - http://hacks.catdancer.ws/list-writer1.patch | patch