diff options
Diffstat (limited to 'lisp.c')
| -rw-r--r-- | lisp.c | 29 |
1 files changed, 18 insertions, 11 deletions
@@ -154,17 +154,17 @@ value *reverse(value *list) { } void println_value(value *val) { - print_value(val, -1); - //print_value(val, 50); + print_value(global_env, val, -1); + //print_value(global_env, val, 50); printf("\n"); } void println_value_shallow(value *val) { - print_value(val, 0); + print_value(global_env, val, 0); printf("\n"); } -void print_value(value *val, int depth) { +void print_value(env *e, value *val, int depth) { if(!val) { return; } switch (val->type) { case VT_INT: @@ -176,7 +176,14 @@ void print_value(value *val, int depth) { break; case VT_SYMBOL: - printf("%s", val->as.sym); + value *symbol_found = env_lookup(e, val->as.sym); + if (!depth || !symbol_found || + symbol_found->type == VT_PROCEDURE || + symbol_found->type == VT_LAMBDA) { + printf("%s", val->as.sym); + return; + } + print_value(e, symbol_found, depth-1); break; case VT_STRING: @@ -193,19 +200,19 @@ void print_value(value *val, int depth) { return; } printf("("); - print_value(force_thunk(car(val)), depth-1); + print_value(e, force_thunk(car(val)), depth-1); value *p_cdr = cdr(val); p_cdr = force_thunk(p_cdr); while (p_cdr->type == VT_PAIR || p_cdr->type == VT_THUNK) { printf(" "); - print_value(car(p_cdr), depth-1); + print_value(e, car(p_cdr), depth-1); p_cdr = cdr(p_cdr); p_cdr = force_thunk(p_cdr); } if(p_cdr->type != VT_NIL) { printf(" . "); - print_value(p_cdr, depth-1); + print_value(e, p_cdr, depth-1); } printf(")"); break; @@ -215,7 +222,7 @@ void print_value(value *val, int depth) { printf("<lambda>"); return; } - print_value( + print_value(val->as.lambda.env, cons(make_symbol("λ"), cons(val->as.lambda.params, val->as.lambda.body) ), @@ -241,7 +248,7 @@ void print_value(value *val, int depth) { printf("<thunk>"); return; } - print_value(force_thunk(val), depth-1); + print_value(val->as.thunk.env, force_thunk(val), depth-1); break; default: printf("\n<unknown>[as str:%s][as f:%f][as int:%d]\n", val->as.str, val->as.d, val->as.i); @@ -433,7 +440,7 @@ value *procedure_load_module(env *e, value *args) { if (fst_arg->type != VT_STRING) { printf("error: not a string:"); - print_value(fst_arg, 3); + print_value(global_env, fst_arg, 3); return make_error("not a string: "); } |
