summaryrefslogtreecommitdiffstats
path: root/lib.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2023-06-30 21:42:48 -0700
committerKaz Kylheku <kaz@kylheku.com>2023-06-30 21:42:48 -0700
commit349c01fff273ffcaf5d46873121a067eb82f7997 (patch)
treec4d69d70054d73a923512f1dfe9231c8f3ce9196 /lib.c
parentd7ea45f4c26ff460d062f24f3fbb33c018874dcf (diff)
downloadtxr-349c01fff273ffcaf5d46873121a067eb82f7997.tar.gz
txr-349c01fff273ffcaf5d46873121a067eb82f7997.tar.bz2
txr-349c01fff273ffcaf5d46873121a067eb82f7997.zip
Callable integers become assignable places.
* lib.c (dwim_set): Handle seq argument being an integer or range. * tests/012/callable.tl: A few tests. * txr.1: Documented.
Diffstat (limited to 'lib.c')
-rw-r--r--lib.c96
1 files changed, 66 insertions, 30 deletions
diff --git a/lib.c b/lib.c
index 086041a0..44f5005f 100644
--- a/lib.c
+++ b/lib.c
@@ -13134,42 +13134,78 @@ val replace(val seq, val items, val from, val to)
val dwim_set(val place_p, val seq, varg vargs)
{
val self = lit("index/range assignment");
+ type_t st = type(seq);
- switch (type(seq)) {
- case COBJ:
- if (type(seq) == COBJ) {
- if (seq->co.cls == hash_cls) {
- args_normalize_least(vargs, 3);
-
- switch (vargs->fill) {
- case 2:
- (void) sethash(seq, vargs->arg[0], vargs->arg[1]);
- break;
- case 3:
- if (vargs->list)
- goto excargs;
- (void) sethash(seq, vargs->arg[0], vargs->arg[2]);
- break;
- default:
- goto fewargs;
+ switch (st) {
+ case NUM:
+ case BGNUM:
+ case RNG:
+ {
+ args_normalize_least(vargs, 3);
+ switch (vargs->fill) {
+ case 2:
+ {
+ val arg = vargs->arg[0];
+ val newval = vargs->arg[1];
+ switch (type(arg)) {
+ case NUM:
+ case BGNUM:
+ case RNG:
+ goto notplace;
+ default:
+ if (st == RNG) {
+ range_bind (x, y, seq);
+ if (!place_p && listp(arg))
+ goto notplace;
+ return replace(arg, newval, x, y);
+ } else {
+ (void) refset(arg, seq, newval);
+ return seq;
+ }
+ }
}
+ case 1:
+ case 0:
+ goto fewargs;
+ default:
+ goto excargs;
+ }
+ }
+ case COBJ:
+ if (seq->co.cls == hash_cls) {
+ args_normalize_least(vargs, 3);
- return seq;
+ switch (vargs->fill) {
+ case 2:
+ (void) sethash(seq, vargs->arg[0], vargs->arg[1]);
+ break;
+ case 3:
+ if (vargs->list)
+ goto excargs;
+ (void) sethash(seq, vargs->arg[0], vargs->arg[2]);
+ break;
+ case 1:
+ case 0:
+ goto fewargs;
+ default:
+ goto excargs;
}
- if (obj_struct_p(seq)) {
- {
- val lambda_set_meth = get_special_slot(seq, lambda_set_m);
- if (lambda_set_meth) {
- (void) funcall(method_args(seq, lambda_set_s, vargs));
- return seq;
- }
+
+ return seq;
+ }
+ if (obj_struct_p(seq)) {
+ {
+ val lambda_set_meth = get_special_slot(seq, lambda_set_m);
+ if (lambda_set_meth) {
+ (void) funcall(method_args(seq, lambda_set_s, vargs));
+ return seq;
}
- if (get_special_slot(seq, car_m))
- goto list;
- type_mismatch(lit("~a: object ~s lacks "
- "~s or ~s method"),
- self, seq, lambda_set_s, car_s, nao);
}
+ if (get_special_slot(seq, car_m))
+ goto list;
+ type_mismatch(lit("~a: object ~s lacks "
+ "~s or ~s method"),
+ self, seq, lambda_set_s, car_s, nao);
}
/* fallthrough */
default: