summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2018-11-27 07:04:02 -0800
committerKaz Kylheku <kaz@kylheku.com>2018-11-27 07:04:02 -0800
commit38d30d7ce812bcccc5de475dd272eda9fb87e579 (patch)
treea59e3b252838290bb5c4499995d4d20cc3ea67d5
parent472d9fe5fe1e89eaad0453830ae57ad59846cdb8 (diff)
downloadtxr-38d30d7ce812bcccc5de475dd272eda9fb87e579.tar.gz
txr-38d30d7ce812bcccc5de475dd272eda9fb87e579.tar.bz2
txr-38d30d7ce812bcccc5de475dd272eda9fb87e579.zip
case macros: bugfixes for evaluated keys.
* eval.c: Fix incorrect treatment of cases like (caseql* ((a b) ...)). The check for evaluation must come before we do the keys = car(keys) transformation. Also, hash_keys must be updated to the evaluated keys, otherwise if the hash table optimization is used, the table will contain the original expressions as the keys, not their values.
-rw-r--r--eval.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/eval.c b/eval.c
index e1c75197..9219c8d4 100644
--- a/eval.c
+++ b/eval.c
@@ -3944,16 +3944,16 @@ static val me_case(val form, val menv)
if (keys == t)
eval_error(form_orig, lit("~s: symbol t used as key"), casesym, nao);
- if (consp(keys) && !cdr(keys))
- keys = car(keys);
-
if (star) {
if (atom(keys))
- keys = eval(keys, nil, form);
+ hash_keys = cons(keys = eval(keys, nil, form), nil);
else
- keys = eval(cons(list_s, keys), nil, form);
+ hash_keys = keys = eval(cons(list_s, keys), nil, form);
}
+ if (consp(keys) && !cdr(keys))
+ keys = car(keys);
+
if (atom(keys)) {
sethash(hash, keys, index);
if (!compares_with_eq(keys))