-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrepl.scm
60 lines (50 loc) · 1.48 KB
/
repl.scm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
;; LeeScheme/repl.scm. Copyright (C) Lee Richard Boynton, 1993-2000.
;
; REPL - a read-eval-print-loop and miscellaneous utilities.
;
(standard-io)
(system:enable-keyboard-interrupts #t)
(begin (newline) (display (system:version)) (newline) (newline))
(require 'apropos)
;
;The read-eval-print-loop global variables.
;
(define system:*prompt* "? ")
(define system:*result-prompt* "= ")
(define (system:*abort-hook*) #t) ; called after an error or an interrupt
(define (system:*exec-hook*) #t) ; called before executing toplevel expression
(define exit system:exit)
(define (system:repl)
(define (void? obj)
(eq? obj system:*void*))
(define (repl:eval expr)
(let ((code (compile expr)))
(system:*exec-hook*)
(code)))
(let ((expr #f) (result #f))
(do () ((eof-object? expr))
(case (call-with-current-continuation
(lambda (restart-repl)
(set! system:*restart* restart-repl)
(system:*abort-hook*)
(system:enable-interrupts)
(do () ((eof-object? expr) 'eof)
(display system:*prompt*)
(set! expr (read))
(if (not (eof-object? expr))
(begin
(set! result (repl:eval expr))
(if (not (void? result))
(begin
(display system:*result-prompt*)
(write result)
(newline))))))))
((eof)
(print "end of input!")
(system:exit))
(else
(standard-io)
(system:print-error))))))
(let ((config (system:find-file "config.scm")))
; (if config (load config))
(system:repl))