diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2012-02-18 17:43:56 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2012-02-18 17:43:56 -0800 |
commit | d14ddd48c53f3d9ec960782c75f657a627456d22 (patch) | |
tree | f966df8f17c1a532a41ffa7c749edb0fd95418f5 /eval.c | |
parent | 3b1e713d392d607a37e9f6d1520c4f9f584d014d (diff) | |
download | txr-d14ddd48c53f3d9ec960782c75f657a627456d22.tar.gz txr-d14ddd48c53f3d9ec960782c75f657a627456d22.tar.bz2 txr-d14ddd48c53f3d9ec960782c75f657a627456d22.zip |
Allow braced output variables to actually be arbitrary substitutions.
* eval.c (subst_vars): Treat the variable as an arbitrary
expression rather than just a symbol.
* match.c (subst_vars): Likewise.
* parser.y (o_var): Further simplification. The first item in
an output var is an expr and not an IDENT.
* txr.1: Updated.
* txr.vim: Likewise.
Diffstat (limited to 'eval.c')
-rw-r--r-- | eval.c | 36 |
1 files changed, 15 insertions, 21 deletions
@@ -1118,29 +1118,23 @@ static val subst_vars(val forms, val env) val sym = first(form); if (sym == var_s) { - val sym = second(form); + val expr = second(form); val pat = third(form); val modifiers = fourth(form); - val pair = lookup_var(env, sym); - - if (pair) { - val str = cdr(pair); - - if (!stringp(str) && !listp(str)) - str = format(nil, lit("~a"), str, nao); - - if (pat) - forms = cons(str, cons(pat, rest(forms))); - else if (modifiers) - forms = cons(format_field(str, modifiers, nil, - curry_123_1(func_n3(eval), env, form)), - rest(forms)); - else - forms = cons(str, rest(forms)); - continue; - } - uw_throwf(query_error_s, lit("unbound variable ~a"), - sym, nao); + val str = eval(expr, env, form); + + if (!stringp(str) && !listp(str)) + str = format(nil, lit("~a"), str, nao); + + if (pat) + forms = cons(str, cons(pat, rest(forms))); + else if (modifiers) + forms = cons(format_field(str, modifiers, nil, + curry_123_1(func_n3(eval), env, form)), + rest(forms)); + else + forms = cons(str, rest(forms)); + continue; } else if (sym == quasi_s) { val nested = subst_vars(rest(form), env); list_collect_append(iter, nested); |