Shakti tutorial


k9: Manual

This manual is for Shakti (k9) build 2020.11.16.

The Shakti programming language is the work of Arthur Whitney and the team at Shakti. The language comes from a lineage of similar languages going back to APL. It’s also known as k9 given the similarties to k, k2, ..., k6, k7 and the fact that Arthur also wrote those. k9 is still under development so expect a bit of syntax change and likley even more improvements.

Learning k9 means code like {x@(!#x)+\!#y} is clear and actually prefered to something much longer and verbose. You’ll have to go a bit down the rabbit hole before it starts to come together but once it does you’ll probably be happy you gave it a chance and end up learning a few things. You’ll understand how fast k9 can be in processing and analyzing data and how terse code is less likley to contain errors. Unfortunatley you will be less likley to be content using more bloated and slow frameworks.

Alas this manual is not as elegant as the k9 language such that the text version of this document is almost as big as the binary of the language.

The built-in reference screen (\) containing all the k9 commands.

Universal database, webserver and language -- full stack -- fast

 select A by B from T where Cupdate A from T
 count first last sum min max *[avg var dev med ..]
 x,y      / insertupsertunion, equi+asof leftjoin
 x+y      / equi+asof outerjoin (e.g. combine markets through time)
 x#y      / take/intersect
 x_y      / drop/difference

Verb                      Adverb               Type              System
:    x         y          f/  over  c/  +join  bool 011b         \l a.k
+    flip      plus       f\  scan  c\  +split int  0N 0 2 3     \t:n x
-    negate    minus      f'  each  v'  +has   flt  0n 0 2 3.    \u:n x
*    first     times      f': eachp v': +bin   char " ab"        \v
%              divide     f/: eachr ([n;]f)/:  name ``ab         \w
&    where     min/and    f\: eachl ([n;]f)\:  uuid              \cd x
|    reverse   max/or
<    asc       less              .z.[md]       date 2001.01.01
>    dsc       more              .z.[hrstuv]   time 12:34:56.123456789
=    group     equal      I/O
~    not       match      0:  r/w line         Class             \f
!    enum      key        1:  r/w byte         List (2;3.4;`a)   \ft x
,    enlist    cat       *2:  r/w data         Dict `i`f!(2;3.4) \fl x
^    sort   [f]cut       *3:  k-ipc set        Func {[a;b]a+b}   \fc x
#    count  [f]take      *4:  https get        Expr :a+b
_    floor  [f]drop
$    string    cast+                           Table
?    unique+   find+      $[b;x;y] if else     t:[[]i:2 3;f:3 4.;s:`a`b]
@    type   [f]at         @[x;i;f[;y]] amend   utable [[b:..]a:..]
.    value  [f]dot        .[x;i;f[;y]] dmend   xtable `..![[]a:..]
sqrt sqr exp log sin cos div mod bar .. freq rank msum .. in bin within ..
\\   exit      / comment  *[if do while select[a;b;t;c]]

`csv?`csv t    / read/write csv
`json?`json t  / read/write json
-python:   import k;k.k('+',2,3)
-nodejs: require('k').k('+',2,3)
*ffi: "./"5:`f!"i"  /I f(I i){return 2+i;}       //cblas ..
*c/k: "./"5:`f!1    /K f(K x){return ki(2+xi);}  //feeds ..

*enterprise[unlimited data/users/machines/..] +overload