From 926ad2e614f5c4c817e3ed8b560ded9045a7ccba Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Fri, 11 Nov 2016 21:42:19 -0800 Subject: Bugfix in case{q,ql,qual} macro expansion. * eval.c (me_case): The key must be quoted unconditionally whether it's an atom or list. Let's make this subject to the compatibility flag in case someone's code depends on it. * txr.1: Compat notes added. --- eval.c | 23 +++++++++++++++++------ txr.1 | 18 ++++++++++++++++++ 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/eval.c b/eval.c index b6503280..f863e5fd 100644 --- a/eval.c +++ b/eval.c @@ -3157,12 +3157,23 @@ static val me_case(val form, val menv) if (keys == t) eval_error(form_orig, lit("~s: symbol t used as key"), casesym, nao); - ptail = list_collect(ptail, - cons(list(if3(atom(keys), eqfuncsym, memfuncsym), - tformsym, - if3(atom(keys), keys, list(quote_s, keys, nao)), - nao), - forms)); + if (opt_compat && opt_compat <= 156) { + ptail = list_collect(ptail, + cons(list(if3(atom(keys), eqfuncsym, memfuncsym), + tformsym, + if3(atom(keys), + keys, + list(quote_s, keys, nao)), + nao), + forms)); + } else { + ptail = list_collect(ptail, + cons(list(if3(atom(keys), eqfuncsym, memfuncsym), + tformsym, + list(quote_s, keys, nao), + nao), + forms)); + } } if (form && atom(form)) diff --git a/txr.1 b/txr.1 index 39be55b9..054cd670 100644 --- a/txr.1 +++ b/txr.1 @@ -49312,6 +49312,24 @@ of these version values, the described behaviors are provided if is given an argument which is equal or lower. For instance .code "-C 103" selects the behaviors described below for version 105, but not those for 102. +.IP 156 +After version 156, a bug was fixed in the macro expander for +.codn caseq , +.code caseql +and +.codn casequal . +Selecting a compatibility value of 156 or less restores the buggy +behavior. The bug was that single-atom case keys were undergoing +evaluation. For instance +.code "(caseql x (a 0))" +would arrange for the evaluation of +.code a +as a variable, rather than treating it as the symbol +.code a +itself. Beside using the compatibility mechanism, a workaround is to +use a list of keys, exemplified by a rewrite of the foregoing +expression to +.codn "(caseql x ((a) 0))" . .IP 155 After version 155, the .code tok-str -- cgit v1.2.3