summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2014-02-11 14:21:27 -0800
committerKaz Kylheku <kaz@kylheku.com>2014-02-11 14:21:27 -0800
commit5bc1cc4489663efb96f51b941d3b2313d82f7eef (patch)
tree01979bc36b62ad6f50eb21dc07d0868387b198b2
parentefcc64a8003d79538ffe0e85f91b2d94011c20d0 (diff)
downloadtxr-5bc1cc4489663efb96f51b941d3b2313d82f7eef.tar.gz
txr-5bc1cc4489663efb96f51b941d3b2313d82f7eef.tar.bz2
txr-5bc1cc4489663efb96f51b941d3b2313d82f7eef.zip
* eval.c (subst_vars): Bugfix: results of expressions not
treated in the same way as variables: lists not stringified, causing expansions with parentheses, and sometimes errors due to unhandled objects. Also, use tostringp instead of format for stringifying objects. stringifying object. Bugfix.k * match.c (subst_vars): Added comment similar to the one in the subst_vars of eval.c. Removed superfluous conversion code where the str variable is already known to be a string.
-rw-r--r--ChangeLog13
-rw-r--r--eval.c23
-rw-r--r--match.c7
3 files changed, 34 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog
index 44e2a244..fd14c2e9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,18 @@
2014-02-11 Kaz Kylheku <kaz@kylheku.com>
+ * eval.c (subst_vars): Bugfix: results of expressions not
+ treated in the same way as variables: lists not stringified,
+ causing expansions with parentheses, and sometimes errors
+ due to unhandled objects. Also, use tostringp instead of
+ format for stringifying objects.
+ stringifying object. Bugfix.k
+
+ * match.c (subst_vars): Added comment similar to the one in
+ the subst_vars of eval.c. Removed superfluous conversion code where the
+ str variable is already known to be a string.
+
+2014-02-11 Kaz Kylheku <kaz@kylheku.com>
+
* eval.c (apply): Fix regression in dwim operator: not handling
nil object properly. Since dwim now trivially delegates to apply,
apply must recognize nil.
diff --git a/eval.c b/eval.c
index 6024c60b..d97f0cfd 100644
--- a/eval.c
+++ b/eval.c
@@ -1280,17 +1280,24 @@ static val subst_vars(val forms, val env)
val modifiers = fourth(form);
val str = eval(expr, env, form);
+ /* If the object is a list, we let format_field deal with the
+ conversion to text, because the modifiers influence how
+ it is done. */
if (!stringp(str) && !listp(str))
- str = format(nil, lit("~a"), str, nao);
+ str = tostringp(str);
- if (pat)
+ if (pat) {
forms = cons(str, cons(pat, rest(forms)));
- else if (modifiers)
+ } else if (modifiers) {
forms = cons(format_field(str, modifiers, nil,
curry_123_1(func_n3(eval), env, form)),
rest(forms));
- else
+ } else {
+ if (listp(str))
+ str = cat_str(mapcar(func_n1(tostringp), str), lit(" "));
forms = cons(str, rest(forms));
+ }
+
continue;
} else if (sym == quasi_s) {
val nested = subst_vars(rest(form), env);
@@ -1298,8 +1305,12 @@ static val subst_vars(val forms, val env)
forms = cdr(forms);
continue;
} else if (sym == expr_s) {
- val result = eval(rest(form), env, form);
- forms = cons(format(nil, lit("~a"), result, nao), rest(forms));
+ val str = eval(rest(form), env, form);
+ if (listp(str))
+ str = cat_str(mapcar(func_n1(tostringp), str), lit(" "));
+ else if (!stringp(str))
+ str = tostringp(str);
+ forms = cons(str, rest(forms));
continue;
} else {
val nested = subst_vars(form, env);
diff --git a/match.c b/match.c
index 143c4f12..73452c8c 100644
--- a/match.c
+++ b/match.c
@@ -1359,8 +1359,11 @@ static val subst_vars(val spec, val bindings, val filter)
val modifiers = fourth(elem);
val str = txeval(spec, expr, bindings);
+ /* If the object is a list, we let format_field deal with the
+ conversion to text, because the modifiers influence how
+ it is done. */
if (!stringp(str) && !listp(str))
- str = format(nil, lit("~a"), str, nao);
+ str = tostringp(str);
if (pat)
spec = cons(pat, rest(spec));
@@ -1372,8 +1375,6 @@ static val subst_vars(val spec, val bindings, val filter)
} else {
if (listp(str))
str = cat_str(mapcar(func_n1(tostringp), str), lit(" "));
- else
- str = if3(stringp(str), str, tostringp(str));
spec = cons(filter_string_tree(filter, str), rest(spec));
}