1
1
mirror of https://github.com/kanaka/mal.git synced 2024-10-26 22:28:26 +03:00
mal/impls/sml/step1_read_print.sml

28 lines
479 B
Standard ML
Raw Permalink Normal View History

2021-04-07 15:49:00 +03:00
fun read s =
2021-03-25 20:59:11 +03:00
readStr s
2021-04-07 15:49:00 +03:00
fun eval f =
2021-03-25 20:59:11 +03:00
f
2021-04-07 15:49:00 +03:00
fun print f =
2021-04-04 19:18:40 +03:00
prReadableStr f
2021-03-25 20:59:11 +03:00
fun rep s =
2021-04-07 15:49:00 +03:00
s |> read |> eval |> print
2021-03-25 20:59:11 +03:00
handle SyntaxError msg => "SYNTAX ERROR: " ^ msg
2021-03-26 11:08:59 +03:00
| Nothing => ""
2021-03-25 20:59:11 +03:00
fun repl () =
let open TextIO
in (
print("user> ");
case inputLine(stdIn) of
SOME(line) => (
print(rep(line) ^ "\n");
repl ()
)
| NONE => ()
) end
2021-03-29 15:06:10 +03:00
fun main () = repl ()