fsharp: step 4: Added fn* binding and not function.
[jackhill/mal.git] / fsharp / step4_if_fn_do.fs
1 module REPL
2 open System
3
4 let read input =
5 try
6 Reader.read_str input
7 with
8 | Types.ReaderError(msg) ->
9 printfn "%s" msg
10 []
11
12 let eval env ast =
13 try
14 Some(Eval.eval env ast)
15 with
16 | Types.EvalError(msg) ->
17 printfn "%s" msg
18 None
19
20 let print v =
21 v
22 |> Seq.singleton
23 |> Printer.pr_str
24 |> printfn "%s"
25
26 let re env input =
27 read input
28 |> Seq.ofList
29 |> Seq.choose (fun form -> eval env form)
30
31 let rep env input =
32 input
33 |> re env
34 |> Seq.iter (fun value -> print value)
35
36 let getReadlineMode (args : string array) =
37 if args.Length > 0 && args.[0] = "--raw" then
38 Readline.Mode.Raw
39 else
40 Readline.Mode.Terminal
41
42 [<EntryPoint>]
43 let main args =
44 let mode = getReadlineMode args
45 let env = Env.makeRootEnv ()
46
47 re env "(def! not (fn* (a) (if a false true)))" |> Seq.iter ignore
48
49 let rec loop () =
50 match Readline.read "user> " mode with
51 | null -> 0
52 | input ->
53 rep env input
54 loop ()
55 loop ()