1
1
mirror of https://github.com/kanaka/mal.git synced 2024-11-10 12:47:45 +03:00
mal/fsharp/step1_read_print.fs

42 lines
921 B
Forth
Raw Normal View History

2015-02-24 07:22:58 +03:00
module REPL
open System
let read input =
try
Reader.read_str input
with
| Types.ReaderError(msg) ->
printfn "%s" msg
[]
2015-02-24 07:22:58 +03:00
let eval ast =
Some(ast)
2015-02-24 07:22:58 +03:00
let print v =
v
|> Seq.singleton
2015-02-24 07:22:58 +03:00
|> Printer.pr_str
|> printfn "%s"
2015-02-24 07:22:58 +03:00
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 : string array) =
if args.Length > 0 && args.[0] = "--raw" then
Readline.Mode.Raw
else
Readline.Mode.Terminal
2015-02-24 07:22:58 +03:00
[<EntryPoint>]
let rec main args =
let mode = getReadlineMode args
2015-02-24 07:22:58 +03:00
match Readline.read "user> " mode with
| null -> 0
| input ->
rep input
main args