Skip to content

Commit

Permalink
Defining and using a repl-print generic to allow customizing REPL out…
Browse files Browse the repository at this point in the history
…put.
  • Loading branch information
ashinn committed Oct 28, 2024
1 parent 4f3a98b commit f4e3c0f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
19 changes: 12 additions & 7 deletions lib/chibi/repl.scm
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,11 @@
((= (length value) 1) (push-history-value! (car 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)
(let ((thread (current-thread))
(out (repl-out rp)))
Expand All @@ -422,17 +427,17 @@
(null? expr))
(eval expr (repl-env rp))
expr))
(lambda res-list
(lambda res-values
(cond
((not (or (null? res-list)
(equal? res-list (list (if #f #f)))))
(push-history-value-maybe! res-list)
(write/ss (car res-list) out)
((not (or (null? res-values)
(equal? res-values (list undefined-value))))
(push-history-value-maybe! res-values)
(repl-print (car res-values) out)
(for-each
(lambda (res)
(write-char #\space out)
(write/ss res out))
(cdr res-list))
(repl-print res out))
(cdr res-values))
(newline out))))))
expr-list))))))

Expand Down
4 changes: 2 additions & 2 deletions lib/chibi/repl.sld
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

(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)
(chibi ast) (chibi modules) (chibi doc)
(chibi ast) (chibi modules) (chibi doc) (chibi generic)
(chibi string) (chibi io) (chibi optional)
(chibi process) (chibi term edit-line)
(srfi 1)
Expand Down

0 comments on commit f4e3c0f

Please sign in to comment.