1
1
mirror of https://github.com/kanaka/mal.git synced 2024-08-17 09:40:21 +03:00

add core readline

This commit is contained in:
Fabian 2021-04-05 21:46:40 +02:00 committed by Joel Martin
parent 6b14be1285
commit 9c6ae5d723
2 changed files with 9 additions and 1 deletions

View File

@ -118,7 +118,13 @@ val coreIo = [
FN (fn args => args |> map prReadableStr |> String.concatWith " " |> malPrint),
SYMBOL "println",
FN (fn args => args |> map prStr |> String.concatWith " " |> malPrint)
FN (fn args => args |> map prStr |> String.concatWith " " |> malPrint),
SYMBOL "readline",
FN (fn [STRING prompt] => (TextIO.print prompt;
valOrElse (TextIO.inputLine TextIO.stdIn |> Option.map (STRING o (trimr 1)))
(fn () => NIL))
| _ => raise NotApplicable "readline requires a string")
]
fun arithFolder n f (INT next, INT prev) = INT (f (prev, next))

View File

@ -26,6 +26,8 @@ fun identity x = x
fun triml k s = String.extract (s, k, NONE)
fun trimr k s = String.substring (s, 0, String.size s - k)
fun malEscape s = String.translate (fn #"\"" => "\\\""
| #"\n" => "\\n"
| #"\\" => "\\\\"