1
1
mirror of https://github.com/kanaka/mal.git synced 2024-09-11 21:57:38 +03:00
mal/impls/fsharp/step1_read_print.fs

44 lines
965 B
Forth
Raw Permalink Normal View History

2015-02-24 07:22:58 +03:00
module REPL
open System
let READ input =
try
Reader.read_str input
with
| Error.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 =
2015-02-24 07:22:58 +03:00
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 =
if args |> Array.exists (fun e -> e = "--raw") then
Readline.Mode.Raw
else
Readline.Mode.Terminal
2015-02-24 07:22:58 +03:00
[<EntryPoint>]
let main args =
let mode = getReadlineMode args
let rec loop () =
match Readline.read "user> " mode with
| null -> 0
| input ->
REP input
loop()
loop ()