Running K/ngnk
Installing ngn/k Edit
Linux package managers Edit
Arch et al. Edit
ngn/k is available on the AUR package manager; thus it can be conveniently installed on Arch Linux and related distros, like Manjaro.
Compiling from source Edit
The ngn/k repo contains a makefile that will build an executable k
binary. Run make
to build k
, which you can then put into your PATH
.
It also contains repl.k
, which when run provides a convenient REPL environment for interactive programming. It's convenient to add a simple alias such as the following:
alias krepl='rlwrap k ~/sources/k/repl.k'
Building external libraries Edit
ngn/k provides a k.h
header file. When this file is included, it describes an interface that C programs can implement in order to provide shared objects that are linkable from K programs.
Roughly, including external libraries into ngn/k programs consists of three steps:
- Write a K-compatible C program by including the
k.h
header - Compile the C program into a shared object file
- Inside of a K program, load the shared object file and assign it to a verb.
Note that k.h
and libk.so
must be available to your compiler and linker, respectively:
k.h
is available in the ngn/k source code;- The ngn/k makefile includes a target to build
libk.so
.
(The AUR package above installs both of the required files into the standard system directories)
References and Examples Edit
Onikuruma Edit
onikuruma is an implementation of the Oniguruma regular expression library for K. It contains both the required C code and Makefile as examples of how to build K-compatible external libraries, as well as example K code for how to call an external library from K. A short example for reference:
m:`"./libregex.so"2:(`match;2)
m["asd";"someasdstring"]