From fbe0c77a06a711bd746261406e47c16c55e660a8 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 26 Jan 2012 16:20:10 -0800 Subject: * lib.c (listref, listref_l): Negative indices must have semantics consistent with vecref and ranges. --- ChangeLog | 5 +++++ lib.c | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index acef717f..6c942cf2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2012-01-26 Kaz Kylheku + + * lib.c (listref, listref_l): Negative indices must have semantics + consistent with vecref and ranges. + 2012-01-26 Kaz Kylheku * lib.c (cat_str): Throw error if one of the list elements diff --git a/lib.c b/lib.c index 29049969..3dd57738 100644 --- a/lib.c +++ b/lib.c @@ -310,7 +310,7 @@ val sixth(val cons) val listref(val list, val ind) { if (lt(ind, zero)) - return nil; + ind = plus(ind, length_list(list)); for (; gt(ind, zero); ind = minus(ind, one)) list = cdr(list); return car(list); @@ -321,6 +321,9 @@ val *listref_l(val list, val ind) val olist = list; val oind = ind; + if (lt(ind, zero)) + ind = plus(ind, length_list(list)); + for (; gt(ind, zero) && list; ind = minus(ind, one)) list = cdr(list); if (consp(list)) -- cgit v1.2.3