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. --- lib.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'lib.c') 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