2 String >> loadRelative
[
3 | scriptPath scriptDirectory |
4 scriptPath
:= thisContext currentFileName
.
5 scriptDirectory
:= FilePath stripFileNameFor: scriptPath
.
6 FileStream fileIn: (FilePath append: self to: scriptDirectory
)
10 'readline.st' loadRelative
.
11 'util.st' loadRelative
.
12 'types.st' loadRelative
.
13 'reader.st' loadRelative
.
14 'printer.st' loadRelative
.
16 Object subclass: MAL [
17 MAL class >>
READ: input
[
18 ^Reader readStr: input
21 MAL class >>
EVAL: sexp
[
25 MAL class >>
PRINT: sexp
[
26 ^Printer prStr: sexp
printReadably: true
29 MAL class >>
rep: input
[
30 ^self PRINT: (self EVAL: (self READ: input
))
36 historyFile
:= '.mal_history'.
37 ReadLine readHistory: historyFile
.
39 [ input
:= ReadLine readLine: 'user> '. input isNil
] whileFalse: [
40 input isEmpty
ifFalse: [
41 ReadLine addHistory: input
.
42 ReadLine writeHistory: historyFile
.
43 [ (MAL rep: input
) displayNl
]
44 on: MALEmptyInput do: [ #return ]
46 [ :err |
('error: ', err messageText
) displayNl
. #return ].