forked from kanaka/mal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
step1_read_print.fs
41 lines (35 loc) · 910 Bytes
/
step1_read_print.fs
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
module REPL
open System
let READ input =
try
Reader.read_str input
with
| Error.ReaderError(msg) ->
printfn "%s" msg
[]
let EVAL ast =
Some(ast)
let PRINT v =
v
|> Seq.singleton
|> Printer.pr_str
|> printfn "%s"
let REP input =
READ input
|> Seq.ofList
|> Seq.map (fun form -> EVAL form)
|> Seq.filter Option.isSome
|> Seq.iter (fun value -> PRINT value.Value)
let getReadlineMode args =
if args |> Array.exists (fun e -> e = "--raw") then
Readline.Mode.Raw
else
Readline.Mode.Terminal
[<EntryPoint>]
let rec main args =
let mode = getReadlineMode args
match Readline.read "user> " mode with
| null -> 0
| input ->
REP input
main args