Merge pull request #378 from asarhaddon/test-macro-not-changing-function
[jackhill/mal.git] / ts / step1_read_print.ts
1 import { readline } from "./node_readline";
2
3 import { MalType } from "./types";
4 import { readStr } from "./reader";
5 import { prStr } from "./printer";
6
7 // READ
8 function read(str: string): MalType {
9 return readStr(str);
10 }
11
12 // EVAL
13 function evalMal(ast: any, _env?: any): any {
14 // TODO
15 return ast;
16 }
17
18 // PRINT
19 function print(exp: MalType): string {
20 return prStr(exp);
21 }
22
23 function rep(str: string): string {
24 return print(evalMal(read(str)));
25 }
26
27 while (true) {
28 const line = readline("user> ");
29 if (line == null) {
30 break;
31 }
32 if (line === "") {
33 continue;
34 }
35 try {
36 console.log(rep(line));
37 } catch (e) {
38 const err: Error = e;
39 console.error(err.message);
40 }
41 }