From d69c6738731c24a8336f2734cee48547320d589c Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Wed, 5 Apr 2017 21:09:35 -0700 Subject: Indexing in variable subst applies to any sequence. The @{a [3]} syntax in quasiliterals and @(output) now indexes into the original object a if it is any sequence kind, not specifically a list. Otherwise it indexes into its string representation. * eval.c (format_field): Combine the elements of the object with the separator if it is any sequence type other than a string. Subject to compat option. (subst_vars): Avoid converting any kind of sequence to string, rather than just lists. After any field formatting is applied, if the object is any sequence (not just alist), combine the elements with a space. All subect to compat option. * match.c (tx_subst_vars): Same treatment as subst_vars. * txr.1: Compatibility notes added. --- eval.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'eval.c') diff --git a/eval.c b/eval.c index 4b2f32f9..eece7f3d 100644 --- a/eval.c +++ b/eval.c @@ -2528,10 +2528,11 @@ val format_field(val obj, val modifier, val filter, val eval_fun) } } - if (listp(obj)) - str = cat_str(mapcar(func_n1(tostringp), obj), sep); - else - str = if3(stringp(obj), obj, tostringp(obj)); + str = if3(stringp(obj), + obj, + if3(if3(opt_compat && opt_compat <= 174, listp(obj), seqp(obj)), + cat_str(mapcar(func_n1(tostringp), obj), sep), + tostringp(obj))); { val filter_sym = getplist(plist, filter_k); @@ -2587,19 +2588,27 @@ val subst_vars(val forms, val env, val filter) val modifiers = third(form); val str = eval(expr, env, form); - /* If the object is a list, we let format_field deal with the + /* If the object is a sequence, we let format_field deal with the conversion to text, because the modifiers influence how it is done. */ - if (!stringp(str) && !listp(str)) - str = tostringp(str); + str = if3(stringp(str), + str, + if3(if3(opt_compat && opt_compat <= 174, + listp(str), seqp(str)), + str, + tostringp(str))); if (modifiers) { forms = cons(format_field(str, modifiers, filter, curry_123_1(func_n3(eval), env, form)), rest(forms)); } else { - if (listp(str)) - str = cat_str(mapcar(func_n1(tostringp), str), lit(" ")); + if (!stringp(str)) + str = if3(if3(opt_compat && opt_compat <= 174, + listp(str), seqp(str)), + cat_str(mapcar(func_n1(tostringp), str), lit(" ")), + str); + forms = cons(filter_string_tree(filter, str), rest(forms)); } -- cgit v1.2.3