summaryrefslogtreecommitdiffstats
path: root/eval.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2014-07-02 07:04:07 -0700
committerKaz Kylheku <kaz@kylheku.com>2014-07-02 07:04:07 -0700
commitce7f0602f317d02a71ad70e0ce27a0edd8cbde4f (patch)
treea4319042d6d14b7379c7462fd62359ace9933d85 /eval.c
parent4aac1a2a6144d04a047966e295727258bd09a734 (diff)
downloadtxr-ce7f0602f317d02a71ad70e0ce27a0edd8cbde4f.tar.gz
txr-ce7f0602f317d02a71ad70e0ce27a0edd8cbde4f.tar.bz2
txr-ce7f0602f317d02a71ad70e0ce27a0edd8cbde4f.zip
* eval.c (dwim_loc): Support indexing using a list of positions,
such as obtained by the where function. * lib.c (replace_list, replace_str, replace_vec): Allow the from argument to be a list of index positions, possibly empty. * txr.1: Condensed syntactic descriptions under dwim operator. Range Indexing section no longer says that the value nil can be used as either endpoint of a range. This will not work any longer since a "from" value of nil looks like an empty list of indexes. Documented new behavior under replace, and shortened documentation for replace-list, replace-str and replace-vec.
Diffstat (limited to 'eval.c')
-rw-r--r--eval.c39
1 files changed, 29 insertions, 10 deletions
diff --git a/eval.c b/eval.c
index 2d4243df..0d2a6144 100644
--- a/eval.c
+++ b/eval.c
@@ -1503,15 +1503,22 @@ static loc dwim_loc(val form, val env, val op, val newform, val *retval)
val index = first(args);
if (consp(index)) {
+ cons_bind (from, to, index);
+
+ if (listp(to)) {
+ from = index;
+ to = colon_k;
+ }
+
if (op == set_s) {
val newval = eval(newform, env, form);
- replace_str(obj, newval, car(index), cdr(index));
+ replace_str(obj, newval, from, to);
*retval = newval;
} else if (op == del_s) {
- *retval = sub_str(obj, car(index), cdr(index));
- replace_str(obj, nil, car(index), cdr(index));
+ *retval = sub_str(obj, from, to);
+ replace_str(obj, nil, from, to);
} else {
- eval_error(form, lit("[~s ~s]: ranges allow only set and del operators"),
+ eval_error(form, lit("[~s ~s]: ranges and index lists allow only set and del operators"),
obj, index, nao);
}
@@ -1555,14 +1562,20 @@ static loc dwim_loc(val form, val env, val op, val newform, val *retval)
val index = first(args);
if (consp(index)) {
+ cons_bind (from, to, index);
+
+ if (listp(to)) {
+ from = index;
+ to = colon_k;
+ }
if (op == set_s) {
val newval = eval(newform, env, form);
- replace_vec(obj, newval, car(index), cdr(index));
+ replace_vec(obj, newval, from, to);
*retval = newval;
} else if (op == del_s) {
- *retval = sub_vec(obj, car(index), cdr(index));
- replace_vec(obj, nil, car(index), cdr(index));
+ *retval = sub_vec(obj, from, to);
+ replace_vec(obj, nil, from, to);
} else {
eval_error(form, lit("[~s ~s]: ranges allow only set and del operators"),
obj, index, nao);
@@ -1596,17 +1609,23 @@ static loc dwim_loc(val form, val env, val op, val newform, val *retval)
} else if (consp(index)) {
val newlist;
val tempform;
+ cons_bind (from, to, index);
+
+ if (listp(to)) {
+ from = index;
+ to = colon_k;
+ }
if (op == set_s) {
val newval = eval(newform, env, form);
- newlist = replace_list(obj, newval, car(index), cdr(index));
+ newlist = replace_list(obj, newval, from, to);
tempform = list(op, second(form),
cons(quote_s, cons(newlist, nil)), nao);
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));
+ *retval = sub_list(obj, from, to);
+ newlist = replace_list(obj, nil, from, to);
tempform = list(op, second(form),
cons(quote_s, cons(newlist, nil)), nao);
op_modplace(tempform, env);