BQN, Lettuce and Tomato
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.
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.
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)
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.
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
⟨ 0 1 2 3 4 5 6 7 8 9 ⟩
In our first BQN app, we’re looking at the monadic (aka. taking a single argument) version of the Range function where
AKA iota in other languages (eg. C++)
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
╵ ⟨ 0 0 ⟩ ⟨ 0 1 ⟩ ⟨ 0 2 ⟩
⟨ 1 0 ⟩ ⟨ 1 1 ⟩ ⟨ 1 2 ⟩
⟨ 2 0 ⟩ ⟨ 2 1 ⟩ ⟨ 2 2 ⟩
⟨ 3 0 ⟩ ⟨ 3 1 ⟩ ⟨ 3 2 ⟩
And you can go up to as many dimensions as you’d like.