yorick: Add `yorick-eval` interop support
[jackhill/mal.git] / yorick / step1_read_print.i
1 set_path, get_env("YORICK_MAL_PATH") + ":" + get_path()
2 require, "reader.i"
3 require, "printer.i"
4
5 func READ(str)
6 {
7 return read_str(str)
8 }
9
10 func EVAL(exp, env)
11 {
12 if (structof(exp) == MalError) return exp
13 return exp
14 }
15
16 func PRINT(exp)
17 {
18 if (structof(exp) == MalError) return exp
19 return pr_str(exp, 1)
20 }
21
22 func REP(str)
23 {
24 return PRINT(EVAL(READ(str), ""))
25 }
26
27 func main(void)
28 {
29 stdin_file = open("/dev/stdin", "r")
30 while (1) {
31 write, format="%s", "user> "
32 line = rdline(stdin_file, prompt="")
33 if (!line) break
34 if (strlen(line) > 0) {
35 result = REP(line)
36 if (structof(result) == MalError) write, format="Error: %s\n", result.message
37 else write, format="%s\n", result
38 }
39 }
40 write, ""
41 }
42
43 main;