浏览代码

upd pp; upd readme

txlyre 2 周之前
父节点
当前提交
92567117fc
共有 2 个文件被更改,包括 103 次插入2 次删除
  1. 96 2
      jk.c
  2. 7 0
      readme.md

+ 96 - 2
jk.c

@@ -558,6 +558,94 @@ struct _Nt{enum Ntag_t{N_STRAND,N_LITERAL,N_INDEX1,N_INDEX2,N_FUN,N_MONAD,N_DYAD
   Nt*a;
   Nt*b;
   Nt*c;};
+S Nshow(Nt*n){SW(n->tag){CS N_STRAND:{Bt*buf=Bnew();
+      for(Z i=0;i<n->l->length;i++){if(i!=0)BappendS(buf,",:");
+        S s=Nshow(n->l->data[i]);
+        BappendS(buf,s);
+        FR(s);}
+      R Bread(buf);}
+    CS N_LITERAL:R Vshow(n->v);
+    CS N_INDEX1:{S s;
+      Bt*buf=Bnew();
+      s=Nshow(n->a);
+      BappendS(buf,s);
+      FR(s);
+      Bappend(buf,' ');
+      s=Nshow(n->b);
+      BappendS(buf,s);
+      FR(s);R Bread(buf);}
+    CS N_INDEX2:{S s;
+      Bt*buf=Bnew();
+      s=Nshow(n->a);
+      BappendS(buf,s);
+      FR(s);
+      Bappend(buf,' ');
+      s=Nshow(n->b);
+      BappendS(buf,s);
+      FR(s);
+      Bappend(buf,' ');
+      s=Nshow(n->c);
+      BappendS(buf,s);
+      FR(s);R Bread(buf);}
+    CS N_FUN:{Bt*buf=Bnew();
+      Bappend(buf,':');
+      S s=Nshow(n->a);
+      BappendS(buf,s);
+      FR(s);R Bread(buf);}
+    CS N_MONAD:CS N_HOOK:CS N_BOND:CS N_OVER:{S s;
+      Bt*buf=Bnew();
+      s=Nshow(n->a);
+      BappendS(buf,s);
+      FR(s);
+      s=Nshow(n->b);
+      BappendS(buf,s);
+      FR(s);R Bread(buf);}
+    CS N_DYAD:{S s;
+      Bt*buf=Bnew();
+      s=Nshow(n->b);
+      BappendS(buf,s);
+      FR(s);
+      s=Nshow(n->a);
+      BappendS(buf,s);
+      FR(s);
+      s=Nshow(n->c);
+      BappendS(buf,s);
+      FR(s);R Bread(buf);}
+    CS N_ADV:CS N_PARTIAL_CONJ:{Bt*buf=Bnew();
+      S s=Nshow(n->a);
+      BappendS(buf,s);
+      FR(s);
+      BappendS(buf,n->av->name);R Bread(buf);}
+    CS N_CONJ:{S s;
+      Bt*buf=Bnew();
+      s=Nshow(n->a);
+      BappendS(buf,s);
+      FR(s);
+      BappendS(buf,n->av->name);
+      s=Nshow(n->b);
+      BappendS(buf,s);
+      FR(s);R Bread(buf);}
+    CS N_FORK:{S s;
+      Bt*buf=Bnew();
+      s=Nshow(n->a);
+      BappendS(buf,s);
+      FR(s);
+      s=Nshow(n->b);
+      BappendS(buf,s);
+      FR(s);
+      s=Nshow(n->c);
+      BappendS(buf,s);
+      FR(s);R Bread(buf);}
+    CS N_BIND:{S s;
+      Bt*buf=Bnew();
+      s=Nshow(n->a);
+      BappendS(buf,s);
+      FR(s);
+      Bappend(buf,':');
+      s=Nshow(n->b);
+      BappendS(buf,s);
+      FR(s);R Bread(buf);}}
+  R sdup("<?>");}
 Vt*_fork_m(St*st,vt*self,Vt*x){vt*f=Ai(self->bonds,0);
   vt*g=Ai(self->bonds,1);
   vt*h=Ai(self->bonds,2);
@@ -635,7 +723,11 @@ Vt*Swalk(St*st,Nt*node){if(!node)R st->nil;
     vt*nv=vnew();
     if(argc>0)nv->is_fun=T;
     nv->bonds=An();
-    nv->name=sdup(argc==0?":...":argc==1?":x":":xy");
+    S s=Nshow(node->a);
+    Z z=strlen(s)+2;
+    nv->name=ma(z);
+    snprintf(nv->name,z,":%s",s);
+    FR(s);
     nv->rank[0]=0;
     nv->rank[1]=0;
     nv->rank[2]=0;
@@ -754,6 +846,8 @@ Vt*Swalk(St*st,Nt*node){if(!node)R st->nil;
     nca(b,&argc);
     if(argc!=0)b=Nn1(N_FUN,b);
     Vt*r=Swalk(st,b);
+    if(argc!=0){FR(r->val.verb->name);
+      r->val.verb->name=l->val.symbol;}
     if(r->tag==VERB&&argc==0)r->val.verb->mark=T;
     Vt*ov=Tget(st->env,l->val.symbol);
     if(ov&&ov->tag==VERB&&ov->val.verb->is_fun&&r->tag==VERB&&r->val.verb->is_fun){if(!ov->val.verb->monad&&r->val.verb->monad){As(ov->val.verb->bonds,0,r->val.verb->bonds->data[0]);
@@ -783,7 +877,7 @@ Vt*vunbind(St*st,vt*self,Vt*x){if(xt==SYM){Tdelete(st->env,xY);R st->nil;}
 Vt*vobverse(St*st,vt*self,Vt*x,Vt*y){if(xt==VERB&&yt==VERB){vt*vx=xV;
     if(!yV->monad)
       R st->udf;
-    if(strcmp(vx->name,":...")==0||strcmp(vx->name,":x")==0||strcmp(vx->name,":xy")==0)R st->udf;
+    if(vx->is_fun)R st->udf;
     if(Thas(Inverses,vx->name))R st->udf;  
     Tset(Inverses,vx->name,yV);R st->nil;}
   R st->udf;}

+ 7 - 0
readme.md

@@ -84,6 +84,13 @@ l 3
 9 18 27 36 45 54 63 72 81
 ```
 
+## Duplicate zeroes keeping the same shape
+```
+    dzks:##]#.(>0=)
+    dzks 1 0 2 3 0 4 5 0
+1 0 0 2 3 0 0 4
+```
+
 # Quick reference (also available in the interpreter itself)
 
 ```