diff options
| author | Joel Martin <github@martintribe.org> | 2014-03-24 16:32:24 -0500 |
|---|---|---|
| committer | Joel Martin <github@martintribe.org> | 2014-03-24 16:32:24 -0500 |
| commit | 3169070063b2cb877200117ebb384269d73bcb93 (patch) | |
| tree | 23de3db1ea5c37afd21a45b6ed7771f56a08c0c4 /c/step0_repl.c | |
| download | mal-3169070063b2cb877200117ebb384269d73bcb93.tar.gz mal-3169070063b2cb877200117ebb384269d73bcb93.zip | |
Current state of mal for Clojure West lighting talk.
Diffstat (limited to 'c/step0_repl.c')
| -rw-r--r-- | c/step0_repl.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/c/step0_repl.c b/c/step0_repl.c new file mode 100644 index 0000000..f6d8048 --- /dev/null +++ b/c/step0_repl.c @@ -0,0 +1,44 @@ +#include <stdlib.h> +#include <stdio.h> +#include <unistd.h> + +#ifdef USE_READLINE + #include <readline/readline.h> + #include <readline/history.h> +#else + #include <editline/readline.h> +#endif + +char *READ(char prompt[]) { + char *line; + line = readline(prompt); + if (!line) return NULL; // EOF + add_history(line); // Add input to history. + return line; +} + +char *EVAL(char *ast, void *env) { + return ast; +} + +char *PRINT(char *exp) { + return exp; +} + +int main() +{ + char *ast, *exp; + char prompt[100]; + + // Set the initial prompt + snprintf(prompt, sizeof(prompt), "user> "); + + for(;;) { + ast = READ(prompt); + if (!ast) return 0; + exp = EVAL(ast, NULL); + g_print("%s\n", PRINT(exp)); + + free(ast); // Free input string + } +} |
