Current state of mal for Clojure West lighting talk.
[jackhill/mal.git] / c / step0_repl.c
1 #include <stdlib.h>
2 #include <stdio.h>
3 #include <unistd.h>
4
5 #ifdef USE_READLINE
6 #include <readline/readline.h>
7 #include <readline/history.h>
8 #else
9 #include <editline/readline.h>
10 #endif
11
12 char *READ(char prompt[]) {
13 char *line;
14 line = readline(prompt);
15 if (!line) return NULL; // EOF
16 add_history(line); // Add input to history.
17 return line;
18 }
19
20 char *EVAL(char *ast, void *env) {
21 return ast;
22 }
23
24 char *PRINT(char *exp) {
25 return exp;
26 }
27
28 int main()
29 {
30 char *ast, *exp;
31 char prompt[100];
32
33 // Set the initial prompt
34 snprintf(prompt, sizeof(prompt), "user> ");
35
36 for(;;) {
37 ast = READ(prompt);
38 if (!ast) return 0;
39 exp = EVAL(ast, NULL);
40 g_print("%s\n", PRINT(exp));
41
42 free(ast); // Free input string
43 }
44 }