mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-06-22 22:06:40 +02:00
Defining and using a repl-print generic to allow customizing REPL output.
This commit is contained in:
parent
4f3a98b2b3
commit
f4e3c0fd0b
2 changed files with 14 additions and 9 deletions
|
@ -402,6 +402,11 @@
|
||||||
((= (length value) 1) (push-history-value! (car value)))
|
((= (length value) 1) (push-history-value! (car value)))
|
||||||
(else (push-history-value! value))))
|
(else (push-history-value! value))))
|
||||||
|
|
||||||
|
(define-generic repl-print)
|
||||||
|
|
||||||
|
(define-method (repl-print obj (out output-port?))
|
||||||
|
(write/ss obj out))
|
||||||
|
|
||||||
(define (repl/eval rp expr-list)
|
(define (repl/eval rp expr-list)
|
||||||
(let ((thread (current-thread))
|
(let ((thread (current-thread))
|
||||||
(out (repl-out rp)))
|
(out (repl-out rp)))
|
||||||
|
@ -422,17 +427,17 @@
|
||||||
(null? expr))
|
(null? expr))
|
||||||
(eval expr (repl-env rp))
|
(eval expr (repl-env rp))
|
||||||
expr))
|
expr))
|
||||||
(lambda res-list
|
(lambda res-values
|
||||||
(cond
|
(cond
|
||||||
((not (or (null? res-list)
|
((not (or (null? res-values)
|
||||||
(equal? res-list (list (if #f #f)))))
|
(equal? res-values (list undefined-value))))
|
||||||
(push-history-value-maybe! res-list)
|
(push-history-value-maybe! res-values)
|
||||||
(write/ss (car res-list) out)
|
(repl-print (car res-values) out)
|
||||||
(for-each
|
(for-each
|
||||||
(lambda (res)
|
(lambda (res)
|
||||||
(write-char #\space out)
|
(write-char #\space out)
|
||||||
(write/ss res out))
|
(repl-print res out))
|
||||||
(cdr res-list))
|
(cdr res-values))
|
||||||
(newline out))))))
|
(newline out))))))
|
||||||
expr-list))))))
|
expr-list))))))
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
|
|
||||||
(define-library (chibi repl)
|
(define-library (chibi repl)
|
||||||
(export repl $0 $1 $2 $3 $4 $5 $6 $7 $8 $9)
|
(export repl repl-print $0 $1 $2 $3 $4 $5 $6 $7 $8 $9)
|
||||||
(import (chibi) (only (meta) load-module module-name->file)
|
(import (chibi) (only (meta) load-module module-name->file)
|
||||||
(chibi ast) (chibi modules) (chibi doc)
|
(chibi ast) (chibi modules) (chibi doc) (chibi generic)
|
||||||
(chibi string) (chibi io) (chibi optional)
|
(chibi string) (chibi io) (chibi optional)
|
||||||
(chibi process) (chibi term edit-line)
|
(chibi process) (chibi term edit-line)
|
||||||
(srfi 1)
|
(srfi 1)
|
||||||
|
|
Loading…
Add table
Reference in a new issue