diff options
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | eval.c | 22 |
2 files changed, 27 insertions, 1 deletions
@@ -1,5 +1,11 @@ 2014-02-28 Kaz Kylheku <kaz@kylheku.com> + * eval.c (self_evaluating_p, maybe_quote): New functions. + (expand): Use maybe-quote form macro-time, to not quote + result unnecessarily. + +2014-02-28 Kaz Kylheku <kaz@kylheku.com> + * tests/011/mandel.expected: New file. * tests/011/mandel.txr: New file. @@ -1289,6 +1289,26 @@ static val maybe_progn(val forms) return if3(cdr(forms), cons(progn_s, forms), car(forms)); } +static val self_evaluating_p(val form) +{ + if (nilp(form) || form == t) + return t; + + if (symbolp(form)) + return if2(keywordp(form), t); + + if (atom(form)) + return t; + + return nil; +} + +static val maybe_quote(val form) +{ + if (self_evaluating_p(form)) + return form; + return cons(quote_s, cons(form, nil)); +} static val expand_macrolet(val form, val menv) { @@ -2476,7 +2496,7 @@ tail: val args = rest(form); val args_ex = expand_forms(args, menv); val result = eval_progn(args_ex, make_env(nil, nil, nil), args); - return cons(quote_s, cons(result, nil)); + return maybe_quote(result); } else if (sym == macrolet_s) { return expand_macrolet(form, menv); } else if (sym == symacrolet_s) { |