mirror of
https://github.com/kanaka/mal.git
synced 2024-10-26 22:28:26 +03:00
add core readline
This commit is contained in:
parent
6b14be1285
commit
9c6ae5d723
@ -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))
|
||||
|
@ -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"
|
||||
| #"\\" => "\\\\"
|
||||
|
Loading…
Reference in New Issue
Block a user