Running K/ngnk

From The K Language Wiki

Installing ngn/k

Linux package managers

Arch et al.

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

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

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:

1. Write a K-compatible C program by including the k.h header 2. Compile the C program into a shared object file 3. 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:

1. k.h is available in the ngn/k source code; 2. 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

Onikuruma

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"]

Douglas Mennella's ngnk-libs

README.org