1
0
Fork
You've already forked array
0
forked from loke/array
No description
  • Kotlin 98.4%
  • Emacs Lisp 1%
  • CSS 0.3%
  • JavaScript 0.2%
Find a file
2025年09月23日 15:37:00 +08:00
.idea Fix issues recursive global functions 2025年05月02日 19:34:24 +08:00
.run Implementation of mapAppend 2024年12月23日 16:27:57 +08:00
.woodpecker Allocate and free the surface in the same thread in order to avoid potential leaks 2025年09月15日 02:31:23 +08:00
array Improve error messages for errors while the repl is being initialised 2025年09月22日 15:48:31 +08:00
client-java Some more work on kotter integration 2025年09月20日 00:14:14 +08:00
clientweb Use es modules when running the js compiler 2025年07月03日 03:18:51 +08:00
clientweb2 Constrain guiframe to viewport, add close button 2025年09月23日 16:49:45 +10:00
contrib Don't use a queue for waiting draw requests 2025年09月16日 03:08:59 +08:00
demo Some work on raylib integration 2025年08月23日 01:46:15 +08:00
docs Add support for reading commandline from Kap code 2025年09月21日 23:53:31 +08:00
experimental/kotter-ui Create a generic implementation of the compute queue 2025年09月21日 18:41:05 +08:00
gradle/wrapper Update gradle 2025年05月18日 15:09:40 +08:00
gui Some more work on kotter integration 2025年09月20日 00:14:14 +08:00
gui2 Code cleanup 2025年07月23日 01:40:46 +08:00
jline-kap Fix the prefix/space sequence in the jline reader 2025年05月30日 12:47:58 +08:00
kap-util CSV parser should be able to add row and column labels 2025年07月14日 18:40:38 +08:00
kotlin-js-store Unicode encode and decode functions 2025年08月25日 01:29:03 +08:00
mpbignum Use custom rational arithmetic in the JVM backend 2025年09月17日 21:21:33 +08:00
mpmaths Fixed abug in Complex.pow 2025年09月16日 03:01:14 +08:00
perf-test Use es modules when running the js compiler 2025年07月03日 03:18:51 +08:00
perf-test-jvm Optimisation of stack lookups by removing thread locals 2024年11月29日 23:15:05 +08:00
scripts Added ride start script 2025年03月26日 23:31:42 +08:00
standalonejs Use es modules when running the js compiler 2025年07月03日 03:18:51 +08:00
test-tools More work on formatter 2025年07月27日 01:49:45 +08:00
text-client Improve error messages for errors while the repl is being initialised 2025年09月22日 15:48:31 +08:00
.gitignore Refactored some maths functions 2025年05月01日 22:21:08 +08:00
build.gradle Upgrade Kotlin to 2.2.20-RC2 2025年09月01日 22:10:46 +08:00
COPYING Removed namespace 'graph' 2024年10月09日 21:46:42 +08:00
gradle.properties Symbols with custom syntax should be indicated as such in the completions 2024年08月15日 21:34:10 +08:00
gradlew Upgrade gradle 2021年11月25日 18:46:20 +08:00
gradlew.bat Upgrade gradle 2021年11月25日 18:46:20 +08:00
README.md Allocate and free the surface in the same thread in order to avoid potential leaks 2025年09月15日 02:31:23 +08:00
settings.gradle Some experiments with kotter 2025年09月19日 18:22:48 +08:00

Kap

An implementation of an APL-like language in Kotlin. The implementation is a Kotlin Multiplatform project, and can be compiled to Java, natively and to Javascript.

Summary

Kap is an array-based language that is inspired by APL. The language provides a powerful set of tools that allows the programmer to work with arrays of data instead of element by element. This allows the code to be incredibly compact, and often reduces what would otherwise be tens or even hundreds of lines of code into single line.

Features that sets Kap apart from APL include:

  • Local variable scopes including closures
  • First class functions
  • Custom syntax extensions (this allows features like if and while to be implemented as part of the standard library rather than being part of the language syntax)
  • Lazy evaluation
  • Parallel evaluation
  • Structural under (inspired by BQN)
  • Bigint and rational arithmetic
  • Simple sound and graphic API
  • Line/bar/pie charts

The main website for the project is: https://kapdemo.dhsdevelopments.com/

What the language looks like

As a language based on APL, it uses non-ASCII symbols with most fundamental functions being a single character. This may make the language seem complicated, but it's actually rather simple once one learns the general syntax.

The first line of code in the following example assigns a string to the variable A, and the second line splits the string at instances of -, returning an array of arrays (a string in Kap is nothing more than a one-dimensional array of characters):

A ← "this-is-a-demo"
A ⊂⍨ A≠@-

Typing the above code into the REPL will display the following result:

┌→─────────────────────┐
│"this" "is" "a" "demo"│
└──────────────────────┘

The box around the result indicates that the result is an array. In this case it is a one-dimensional array with 4 elements, each of which is an array of characters (i.e. string).

More examples can be found on the Kap examples web page.

Build dependencies

The Java version of Kap has been tested on Linux, Macos and Windows. The only dependency is Java 21.

Running the JavaFX based UI

The most feature-complete way to run Kap is to use the JVM client. It provides a nicer user interface, an editor, highlighting of the location of errors, ability to draw graphics, and many other features.

To start the client, simply run:

./gradlew gui:run

Running the Linux native version

To build the native Linux version, several dependencies needs to be installed. The development packages for the following libraries needs to be available:

  • Libedit
  • Libcurl
  • ICU
  • Jansson
  • GMP
  • Ncurses
  • Alsa
  • Libffi
  • OpenSSL

Fedora Linux packages

On Fedora, the necessary packages can be installed using:

dnf install java-21-openjdk-devel jansson-devel libicu-devel libffi-devel alsa-lib-devel ncurses-devel libedit-devel gmp-devel libicu-devel libxcrypt-compat libcurl-devel openssl-devel sdl2-compat-devel

Ubuntu packages

On Ubuntu, use the following command to install the dependencies:

apt-get install openjdk-21-jdk libicu-dev libcurl4-openssl-dev libjansson-dev libgmp-dev libedit-dev libasound2-dev libffi-dev libssl-dev libsdl2-dev

Building the Linux version

To build the native Linux binary, run the following command:

./gradlew text-client:linuxMainBinaries

When running the Linux binary, the path to the standard library needs to be passed to the executable:

text-client/build/bin/linux/releaseExecutable/text-client.kexe --lib-path=array/standard-lib

There is currently no support for native compilation on Windows or OSX. As long as the dependencies are available, it should be possible to make it work. Help appreciated if anyone is interested in working on it.

Web client

The application also compiles to Javascript, and it's possible to run it in a browser. Note that some functionality is missing from the Javascript version. For example, network and file operations are currently not implemented.

You can try the web UI here: https://kapdemo.dhsdevelopments.com/clientweb2/

Documentation

Work on the documentation is in progress, but it's still limited.

There is a tutorial which is incomplete: https://kapdemo.dhsdevelopments.com/tutorial.html

The following document explains the differences between Kap and APL, which is useful for readers who already are familiar with APL: https://kapdemo.dhsdevelopments.com/kap-comparison.html

The reference documentation can be found here: https://kapdemo.dhsdevelopments.com/reference.html

Anyone interested in learning more can ask questions on the Matrix channel.

Contributions

The main repository for this project is available from Codeberg: https://codeberg.org/loke/array

For discussions about this project, feel free to join the Matrix channel: #kap:dhsdevelopments.com.