A Simple Array Language

The Klong Book

Documentation | Download

Klong is an array language, like K, but without the ambiguity. If you know K or APL, you may be disappointed by Klong. If you don't know any array languages, it might explode your brain. Use at your own risk!

Programming in Klong

A Klong program is a set of functions that use various pre-defined operators to manipulate lists (vectors) and (multi-dimensional) arrays. Here is a program that checks whether a number x is prime (for x>2):


Note that Klong is a mathematical notation rather than a programming language. If you try to use it like your favorite functional/procedural/OO programming language, you will only get frustrated. Here's an explanation of the above program.

Learn More About Klong

The Reference Manual (klong-ref.txt) provides a complete and detailed semi-formal description of the Klong language. It is probably the best starting point for exploring Klong.

An Introduction to Array Programming in Klong is a brand-new book (2018) that offers a detailed explanation of problem solving in Klong and array languages in general.

The Quick Reference (klong-qref.txt) summarizes the syntax and semantics of the language. It will probably only make sense if you already know K or APL.

Then there is a Really Short Introduction to Klong (klong-intro.txt), which you might want to read if you have never used an array language before.

Finally, if you already know K, here is a (probably incomplete) summary of differences between Klong and K: klong-vs-k.txt.

Compiling and Installing Klong

You can download Klong here: klong20221212.tgz (~170KB, recent changes).

Just in case, here are the previous stable versions: klong20190926.tgz (~156KB), klong20171119.tgz (~120KB, old syntax).

Klong is written in pure ANSI C (C99), so it should compile on any system providing a C compiler. Just run make and make test. It also compiles natively on Plan 9!

To install Klong, just copy the kg binary to /usr/local/bin or some similar place and point the KLONGPATH environment variable to the lib/ directory of the Klong source tree.

Files ending in .kg are Klong programs, you can load them with ]lname or ./kg -l name (with or without the suffix).

Good luck!


In case my Klong interpreter is not fast enough for you, Brian Gurraci has created a vectorized version of Klong named KlongPy. You can find it on GitHub:

contact  |  privacy