-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmocl.lisp
68 lines (59 loc) · 1.91 KB
/
mocl.lisp
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
59
60
61
62
63
64
65
66
67
(shadow '(list-all-packages user-homedir-pathname))
(defun user-homedir-pathname ()
(pathname "/home/pjb/"))
(defun list-all-packages ()
(let ((packages '()))
(do-symbols (s)
(let ((package (symbol-package s)))
(when package
(pushnew package packages))))
packages))
(defmacro handling-errors (&body body)
"
DO: Execute the BODY with a handler for CONDITION and
SIMPLE-CONDITION reporting the conditions.
"
`(handler-case (progn ,@body)
(simple-condition (err)
(format *error-output* "~&~A:~%~?~&"
(class-name (class-of err))
(simple-condition-format-control err)
(simple-condition-format-arguments err))
#-mocl (finish-output *error-output*))
(condition (err)
(format *error-output* "~&~A:~%~A~%" (class-name (class-of err)) err)
#-mocl (finish-output *error-output*))))
(defvar + nil)
(defvar ++ nil)
(defvar +++ nil)
(defvar - nil)
(defvar * nil)
(defvar ** nil)
(defvar *** nil)
(defvar / nil)
(defvar // nil)
(defvar /// nil)
(defun repl ()
"
DO: Implements a minimalist CL REPL.
"
(catch 'repl
(do ((+eof+ (gensym))
(hist 1 (1+ hist)))
(nil)
(format t "~%~A[~D]> " #+mocl *package* #-mocl (package-name *package*) hist)
#-mocl (finish-output)
(handling-errors
(setf - (read *standard-input* nil +eof+))
(when (or (eq - +eof+)
(and (listp -)
(null (rest -))
(member (first -) '(quit exit continue)
:test (function string-equal))))
(return-from repl))
(let ((results (multiple-value-list (eval -))))
(setf +++ ++ ++ + + -
/// // // / / results
*** ** ** * * (first /)))
(format t "~& --> ~{~S~^ ;~% ~}~%" /)
#-mocl (finish-output)))))