txlyre 1 月之前
父节点
当前提交
9bdbf9c96f
共有 3 个文件被更改,包括 26 次插入10 次删除
  1. 2 1
      help.h
  2. 22 8
      jk.c
  3. 2 1
      readme.md

+ 2 - 1
help.h

@@ -133,6 +133,7 @@ const char *V2HELP =\
 "s. dyadic  selfref2      dyadic reference to current function or rhs of bind" "\n"\
 "s. dyadic  selfref2      dyadic reference to current function or rhs of bind" "\n"\
 "F. monadic read          read file (x=0 to read stdin)" "\n"\
 "F. monadic read          read file (x=0 to read stdin)" "\n"\
 "F. dyadic  write         write file (y=0 to write to stderr)" "\n"\
 "F. dyadic  write         write file (y=0 to write to stderr)" "\n"\
+"t. dyadic  cast          cast y to type x" "\n"\
 "t. monadic type          type of x, array=0, verb=1, symbol=2, number=3, char=4, nil=5, udf=6" "\n"\
 "t. monadic type          type of x, array=0, verb=1, symbol=2, number=3, char=4, nil=5, udf=6" "\n"\
 "r. monadic deal          yield random elt of x" "\n"\
 "r. monadic deal          yield random elt of x" "\n"\
 "r. dyadic  roll          roll xdy (note: y is 0-based, so >xr.y for 1-based)" "\n"\
 "r. dyadic  roll          roll xdy (note: y is 0-based, so >xr.y for 1-based)" "\n"\
@@ -167,7 +168,7 @@ const char *AHELP =\
 "xf\\.       eachleft      1-\\.1 2 3 yields 0 -1 -2" "\n"\
 "xf\\.       eachleft      1-\\.1 2 3 yields 0 -1 -2" "\n"\
 "f\":        rank          #\":1 2 3$1 yields 3 3, #\":inf 2 3$1 yields 1 1 1,:1 1 1" "\n"\
 "f\":        rank          #\":1 2 3$1 yields 3 3, #\":inf 2 3$1 yields 1 1 1,:1 1 1" "\n"\
 "xf\":       rank2         1 2 3 *:\":1 1 2 3 yields (,1),:2 2,:3 3 3" "\n"\
 "xf\":       rank2         1 2 3 *:\":1 1 2 3 yields (,1),:2 2,:3 3 3" "\n"\
-"n`         amend         'gw'0 3`'cross' yields 'grows'" "\n"\
+"n`         amend         'gw'0 3`'cross' yields 'grows', 1 0 -1(1+)`!.5 yields 2 3 3 4 6" "\n"\
 "f&.        filter        >;0&.-2!.2 yields 1 2, basically shortcut for ]#.f" "\n"\
 "f&.        filter        >;0&.-2!.2 yields 1 2, basically shortcut for ]#.f" "\n"\
 "f/:        span          =;' '/:'x y z' yields (,'x'),:(,'y'),:(,'z')" "\n"\
 "f/:        span          =;' '/:'x y z' yields (,'x'),:(,'y'),:(,'z')" "\n"\
 "xf/:       stencil       3+//:!10 yields 3 6 9 12 15 18 21 24, shortcut for f\"x|:" "\n"\
 "xf/:       stencil       3+//:!10 yields 3 6 9 12 15 18 21 24, shortcut for f\"x|:" "\n"\

+ 22 - 8
jk.c

@@ -6043,23 +6043,37 @@ value_t *_adverb_amend_dyad(interpreter_t *state, verb_t *self, value_t *x,
     x = verb_enlist(state, NULL, x);
     x = verb_enlist(state, NULL, x);
 
 
   value_t *v = self->bonds->data[0];
   value_t *v = self->bonds->data[0];
-  if (v->tag != ARRAY)
+  if (v->tag != ARRAY && v->tag != VERB)
     v = verb_enlist(state, NULL, v);
     v = verb_enlist(state, NULL, v);
 
 
   if (y->tag != ARRAY)
   if (y->tag != ARRAY)
     y = verb_enlist(state, NULL, y);
     y = verb_enlist(state, NULL, y);
 
 
   list_t *r = list_copy(y->val.array);
   list_t *r = list_copy(y->val.array);
-
   size_t l = x->val.array->length;
   size_t l = x->val.array->length;
 
 
-  list_t *t = v->val.array;
-  for (size_t i = 0; i < t->length; i++) {
-    value_t *n = t->data[i];
-    if (n->tag != NUMBER)
-      break;
+  if (v->tag == VERB) {
+    list_t *t = x->val.array;
+    for (size_t i = 0; i < t->length; i++) {
+      value_t *n = t->data[i];
+      if (n->tag != NUMBER)
+        break;
 
 
-    list_set(r, n->val.number, list_index(x->val.array, i < l ? i : l - 1));
+      value_t *e = list_index(r, n->val.number);
+      if (!e)
+        continue;
+
+      list_set(r, n->val.number, apply_monad(state, v, e));
+    }
+  } else {
+    list_t *t = v->val.array;
+    for (size_t i = 0; i < t->length; i++) {
+      value_t *n = t->data[i];
+      if (n->tag != NUMBER)
+        break;
+
+      list_set(r, n->val.number, list_index(x->val.array, i < l ? i : l - 1));
+    }
   }
   }
 
 
   return value_new_array(r);
   return value_new_array(r);

+ 2 - 1
readme.md

@@ -292,6 +292,7 @@ s. monadic selfref1      monadic reference to current function or rhs of bind or
 s. dyadic  selfref2      dyadic reference to current function or rhs of bind or top-most train
 s. dyadic  selfref2      dyadic reference to current function or rhs of bind or top-most train
 F. monadic read          read file (x=0 to read stdin)
 F. monadic read          read file (x=0 to read stdin)
 F. dyadic  write         write file (y=0 to write to stderr)
 F. dyadic  write         write file (y=0 to write to stderr)
+t. dyadic  cast          cast y to type x
 t. monadic type          type of x, array=0, verb=1, symbol=2, number=3, char=4, nil=5, udf=6
 t. monadic type          type of x, array=0, verb=1, symbol=2, number=3, char=4, nil=5, udf=6
 r. monadic deal          yield random elt of x
 r. monadic deal          yield random elt of x
 r. dyadic  roll          roll xdy (note: y is 0-based, so >xr.y for 1-based)
 r. dyadic  roll          roll xdy (note: y is 0-based, so >xr.y for 1-based)
@@ -323,7 +324,7 @@ xf/.       eachright     1-/.1 2 3 yields 0 1 2
 xf\.       eachleft      1-\.1 2 3 yields 0 -1 -2
 xf\.       eachleft      1-\.1 2 3 yields 0 -1 -2
 f":        rank          #":1 2 3$1 yields 3 3, #":inf 2 3$1 yields 1 1 1,:1 1 1
 f":        rank          #":1 2 3$1 yields 3 3, #":inf 2 3$1 yields 1 1 1,:1 1 1
 xf":       rank2         1 2 3 *:":1 1 2 3 yields (,1),:2 2,:3 3 3
 xf":       rank2         1 2 3 *:":1 1 2 3 yields (,1),:2 2,:3 3 3
-n`         amend         'gw'0 3`'cross' yields 'grows'
+n`         amend         'gw'0 3`'cross' yields 'grows', 1 0 -1(1+)`!.5 yields 2 3 3 4 6
 f&.        filter        >;0&.-2!.2 yields 1 2, basically shortcut for ]#.f
 f&.        filter        >;0&.-2!.2 yields 1 2, basically shortcut for ]#.f
 f/:        span          =;' '/:'x y z' yields (,'x'),:(,'y'),:(,'z')
 f/:        span          =;' '/:'x y z' yields (,'x'),:(,'y'),:(,'z')
 xf/:       stencil       3+//:!10 yields 3 6 9 12 15 18 21 24, shortcut for f"x|:
 xf/:       stencil       3+//:!10 yields 3 6 9 12 15 18 21 24, shortcut for f"x|: