cyclone/scheme/repl.sld
Sören Tempel e3d7b6eed9 Flush current-output-port after writing prompt to it
On Unix-like operating systems stdio.h (which Cyclone seems to use
internally) is line-buffered. As such, the prompt will only be written
after a newline character is written (since the prompt itself doesn't
contain a newline) which is probably not what was
intended here. This commit fixes this issue by always flushing the
current-output-port after writing the prompt string.
2021-08-03 11:36:14 +02:00

59 lines
1.6 KiB
Scheme

;;;; Cyclone Scheme
;;;; https://github.com/justinethier/cyclone
;;;;
;;;; Copyright (c) 2014-2016, Justin Ethier
;;;; All rights reserved.
;;;;
;;;; This module contains the repl library from r7rs.
;;;;
(define-library (scheme repl)
(export
interaction-environment
repl)
(import (scheme base)
(scheme eval)
(scheme read)
(scheme write))
(begin
(define (interaction-environment)
(setup-environment))
(define (repl)
(with-handler
(lambda (obj)
(display "Error: ")
(cond
((error-object? obj)
(display (error-object-message obj))
(if (not (null? (error-object-irritants obj)))
(display ": "))
(for-each
(lambda (o)
(write o)
(display " "))
(error-object-irritants obj)))
((pair? obj)
(when (string? (car obj))
(display (car obj))
(if (not (null? (cdr obj)))
(display ": "))
(set! obj (cdr obj)))
(for-each
(lambda (o)
(write o)
(display " "))
obj))
(else
(display obj)))
(newline)
(repl))
(display "cyclone> ")
(flush-output-port)
(let ((obj (read)))
(if (eof-object? obj)
(newline) ;; Quick way to exit REPL
(let ((c (eval obj)))
(if (eof-object? c)
(display "<EOF>")
(write c))
(newline)
(repl))))))))