BQN, Lettuce and Tomato

Photo by Seriously Low Carb on Unsplash

If you’ve read Part 1 or if you’re just curious to know how to setup your BQN environment, then you’ve definitely come to the right place.

The Compiler

In Part 1 we talked about what BQN is and how I’ve discovered it. In this part we will get a working setup going so that in the next setup we can focus on learning the basics of BQN.

First thing you’ll need is the BQN compiler. I chose the C compiler as it is AFAIK the fastest implementation of BQN.

After checking out the repository, you’ll have to build the project using the instructions you can find on the README page and add the built binaries to your PATH.

The Keyboard

As BQN makes heavy use of unicode characters that are near impossible to type in via a regular keyboard, I strongly advise the use of a keyboard layout.

You can find the Mac version here. Once you’ve installed it, you can add the BQN layout as you would add keyboard for any other language on a Mac and you should be able to easily switch between keyboards.

Pro tip: While learning, as you will not yet know the location of every character by heart, I would recommend to keep the keyboard visible by selecting the Show Keyboard Viewer option which would give you something like this (note that I am holding the alt key to access these characters)

The Editor

If you’re like most people, you’re probably already using VSCode. There is a great plugin built by razetime (who is IMHO a BQN guru) which you can find here.

Once you’ve installed the plugin, you’ll have to configure it to point to the CBQN binary.

And that’s it, you’re good to go.

The Code

Now that you’re all setup, you can launch VSCode and create a new file called hello_world.bqn and paste the following content in it

Congratulations! You have written your first BQN app!

You can run your app by typing ctrl + shift + enter which should open up the terminal and display

The explanation

In our first BQN app, we’re looking at the monadic (aka. taking a single argument) version of the Range function where

Range () is a monadic function that creates arrays of indices (like APL's famous iota function). Each element in the result is its own index.

AKA iota in other languages (eg. C++)

The Wow

The really cool things with almost all BQN functions (as it is an Array Programming Language) is that they work the same way with lists.

If I would provide a list to the functions (instead of a single number) like this

It would return what you would expect it to return

And you can go up to as many dimensions as you’d like.

Cool right?



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store