summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog9
-rw-r--r--eval.c23
-rw-r--r--lib.c4
3 files changed, 26 insertions, 10 deletions
diff --git a/ChangeLog b/ChangeLog
index 23c623da..cdb86cde 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
2012-02-22 Kaz Kylheku <kaz@kylheku.com>
+ * eval.c (dwim_loc): del operator's return value is the
+ deleted range of values. Missing del cases added for single
+ index cases.
+
+ * lib.c (quicksort): Fix pivot selection one more time.
+ (length): Fix bad argument in "not a sequence" error.
+
+2012-02-22 Kaz Kylheku <kaz@kylheku.com>
+
* lib.c (quicksort): Incorrect pivot selection.
2012-02-22 Kaz Kylheku <kaz@kylheku.com>
diff --git a/eval.c b/eval.c
index e9ab5af3..7fc4fb58 100644
--- a/eval.c
+++ b/eval.c
@@ -753,8 +753,8 @@ static val *dwim_loc(val form, val env, val op, val newform, val *retval)
replace_str(obj, newval, car(index), cdr(index));
*retval = newval;
} else if (op == del_s) {
+ *retval = sub_str(obj, car(index), cdr(index));
replace_str(obj, nil, car(index), cdr(index));
- *retval = nil;
} else {
eval_error(form, lit("[~s ~s]: ranges allow only set and del operators"),
obj, index, nao);
@@ -779,11 +779,8 @@ static val *dwim_loc(val form, val env, val op, val newform, val *retval)
chr_str_set(obj, index, newval);
*retval = newval;
} else if (op == del_s) {
- if (lt(index, zero) || length_str_le(obj, index))
- eval_error(form, lit("[~s ~s]: index out of bounds"),
- obj, index, nao);
+ *retval = chr_str(obj, index);
replace_str(obj, nil, index, plus(index, one));
- *retval = nil;
} else {
eval_error(form, lit("[~s ~s]: only set, inc, dec and del can be "
"used for string indices"), obj, index, nao);
@@ -809,15 +806,20 @@ static val *dwim_loc(val form, val env, val op, val newform, val *retval)
replace_vec(obj, newval, car(index), cdr(index));
*retval = newval;
} else if (op == del_s) {
+ *retval = sub_vec(obj, car(index), cdr(index));
replace_vec(obj, nil, car(index), cdr(index));
- *retval = nil;
} else {
eval_error(form, lit("[~s ~s]: ranges allow only set and del operators"),
obj, index, nao);
}
return 0;
} else {
- return vecref_l(obj, first(args));
+ if (op == del_s) {
+ *retval = vecref(obj, index);
+ replace_vec(obj, nil, index, plus(index, one));
+ return 0;
+ }
+ return vecref_l(obj, index);
}
}
case CONS:
@@ -830,6 +832,11 @@ static val *dwim_loc(val form, val env, val op, val newform, val *retval)
val index = first(args);
val cell = obj;
if (bignump(index) || fixnump(index)) {
+ if (op == del_s) {
+ *retval = vecref(obj, index);
+ replace_list(obj, nil, index, plus(index, one));
+ return 0;
+ }
return listref_l(obj, index);
} else if (consp(index)) {
val newlist;
@@ -843,11 +850,11 @@ static val *dwim_loc(val form, val env, val op, val newform, val *retval)
op_modplace(tempform, env);
*retval = newval;
} else if (op == del_s) {
+ *retval = sub_list(obj, car(index), cdr(index));
newlist = replace_list(obj, nil, car(index), cdr(index));
tempform = list(op, second(form),
cons(quote_s, cons(newlist, nil)), nao);
op_modplace(tempform, env);
- *retval = nil;
} else {
eval_error(form, lit("[~s ~s]: ranges allow only set and del operators"),
obj, index, nao);
diff --git a/lib.c b/lib.c
index d405a991..db4b145e 100644
--- a/lib.c
+++ b/lib.c
@@ -3578,7 +3578,7 @@ static void swap(val vec, val i, val j)
static void quicksort(val vec, val lessfun, val keyfun, cnum from, cnum to)
{
if (to - from >= 2) {
- cnum pivot = to + (to - from) / 2;
+ cnum pivot = from + (to - from) / 2;
cnum i, j;
val pval = ref(vec, num_fast(pivot));
val pkval = funcall1(keyfun, pval);
@@ -3673,7 +3673,7 @@ val length(val seq)
case VEC:
return length_vec(seq);
default:
- type_mismatch(lit("length: ~s is not a sequence"), cons, nao);
+ type_mismatch(lit("length: ~s is not a sequence"), seq, nao);
}
}