How to run BQN

We are currently working quickly to make CBQN into the definitive offline implementation. Compilation speed (self-hosted) is good, the only significant core language feature missing is block headers and multiple bodies, and the essential system functions are there. Unless you need to start heavy number crunching right away, I recommend that you use CBQN and make system function or performance requests on Github or the BQN forums.

A lot of development to date has been done in dzaima/BQN and uses features (mainly headers) that aren't in CBQN yet. Scripts in this repository use bqn in the #! line if self-hosted or dzaima/BQN can run them, and dbqn if only dzaima/BQN works.

Self-hosted BQN

See the subsections below for instructions on specific implementations.

This version of BQN is implemented mainly in BQN itself, but a host language supplies basic functionality and can also replace primitives for better performance. This also allows embedding, where programs in the host language can include BQN code. It fully supports all primitives except a few cases of structural Under (), but is still missing some advanced features: block headers and multiple body syntax, derived 1-modifiers, and block returns.

Support in the following languages has been implemented:

Javascript

The online REPL is here. The file docs/bqn.js is zero-dependency Javascript, and can be loaded from HTML or Node.js. For command line use, call the Node.js script bqn.js, passing a file and •args, or -e to execute all remaining arguments directly and print the results. This notebook shows how to run it in an Observable notebook.

CBQN

C sources are kept in the CBQN repository, but they also require the self-hosted bytecode to be built using genRuntime in that repository. The script uses bqn (whatever that is) by default, but can be run with another BQN executable: bqn.js or dzaima/BQN will work. For example, run $ path/BQN/bqn.js genRuntime path/BQN/ to bootstrap using Node.js (slow but should be under a minute even on cheap hardware). Once bootstrapped CBQN itself is the fastest option.

Options are configured at the top of src/main.c. I uncomment #define FORMATTER to get array formatting like this site uses.

CBQN uses the self-hosted runtime to achieve full primitive coverage, and implements specific primitives or parts of primitives natively to speed them up. This means primitives with native support—including everything used by the compiler—are fairly fast while others are much slower.

dzaima/BQN

dzaima/BQN is an implementation in Java created by modifying the existing dzaima/APL, and should be easy to run on desktop Linux and Android. It may be abandoned as dzaima is now working on CBQN. It has almost complete syntax support but incomplete primitive support: major missing functionality is dyadic Depth (), Windows (), and many cases of set functions (⊐⊒∊⍷, mostly with rank >1).

In this repository and elsewhere, dzaima/BQN scripts are called with #! /usr/bin/env dbqn. This requires an executable file dbqn somewhere in your path with the following contents:

#! /bin/bash

java -jar /path/to/dzaima/BQN/BQN.jar "$@"

If compiled with Native Image, nBQN can be used directly instead.

dzaima+reference BQN

This repository contains a dzaima/BQN script dzref that fills in gaps in primitive support with BQN implementations. dzaima/BQN has good enough primitive support that I now almost never use this, but it's still needed for the website generator md.bqn. The command-line arguments are a script to run and followed by the •args to supply to it.

BQN2NGN

BQN2NGN is a prototype implementation in Javascript build to experiment with the langauge, which is now abandoned.