txlyre 8 сар өмнө
parent
commit
96583e02f8
2 өөрчлөгдсөн 67 нэмэгдсэн , 1 устгасан
  1. 1 1
      jk.c
  2. 66 0
      readme.md

+ 1 - 1
jk.c

@@ -1197,7 +1197,7 @@ Vt*vdrop(St*st,vt*self,Vt*x,Vt*y){if(xt==NUM){if(yt!=ARRAY){if(xn==0)R y;
 Vt*vunique(St*st,vt*self,Vt*x){if(xt!=ARRAY||!xad)R x;
 Vt*vunique(St*st,vt*self,Vt*x){if(xt!=ARRAY||!xad)R x;
   Ar*r=An();
   Ar*r=An();
   for(Z i=0;i<xal;i++){B u=T;
   for(Z i=0;i<xal;i++){B u=T;
-    for(Z j=0;j<r->length;j++)if(Veq(xad[j],r->data[j])){u=F;BR;}
+    for(Z j=0;j<r->length;j++)if(Veq(xad[i],r->data[j])){u=F;BR;}
     if(u)Ap(r,xad[i]);}
     if(u)Ap(r,xad[i]);}
   R Vna(r);}
   R Vna(r);}
 Vt*vfind(St*st,vt*self,Vt*x,Vt*y){if(yt!=ARRAY)y=venlist(st,self,y);
 Vt*vfind(St*st,vt*self,Vt*x,Vt*y){if(yt!=ARRAY)y=venlist(st,self,y);

+ 66 - 0
readme.md

@@ -2,6 +2,72 @@
 jk is a recreational tacit array programming language inspired by J and K (so j + k = jk).  
 jk is a recreational tacit array programming language inspired by J and K (so j + k = jk).  
 this is an implementation of the jk interpreter in C. Requires libgc (a.k.a. bdwgc) to build.
 this is an implementation of the jk interpreter in C. Requires libgc (a.k.a. bdwgc) to build.
 
 
+# Examples
+## Compute factorial
+```
+    fac:*/!. / analytic
+    fac 5
+120
+    facr:<.;1?.(]*(f.<)),:(:1) / recursive
+    facr 5
+120
+    / or simply use *.
+    *.5
+120
+```
+
+## Compute Nth fibonacci
+```
+    fib:*x?:(+\|)!2 / iterative
+    fib 10
+55
+    fib"!.10
+1 1 2 3 5 8 13 21 34 55
+    fibr:<.;1?.((f.<)+(f.(<<))),:] / recursive
+    fibr"!.10
+1 1 2 3 5 8 13 21 34 55
+    / or just +.
+    +.!.10
+1 1 2 3 5 8 13 21 34 55
+```
+
+## Remove consecutive duplicates
+```
+    rcd:]&.(1~:".)
+    rcd 'abobaabuuss'
+abobabus
+```
+
+## Check if an array is palindrome
+```
+    ispal:]=:|
+    ispal 'aboba'
+1
+    ispal 'hi'
+0
+```
+
+## Count occurences
+```
+    occs:?,"(#"]@#:)
+    occs 'abracadabra'
+a 5
+b 2
+r 2
+c 1
+d 1
+    occs 'Hello World!'
+H 1
+e 1
+l 3
+o 2
+  1
+W 1
+r 1
+d 1
+! 1
+```
+
 # Quick reference (also available in the interpreter itself)
 # Quick reference (also available in the interpreter itself)
 
 
 ```
 ```