A desk calculator with vectors and quotations.

7afc9d7 Update deps

1 year, 3 months ago

7afc9d7 Update deps

1 year, 3 months ago

An RPN calculator with array operations and quotations.

<> $ 4 5 +
<9> $ p
<> $ [3 4 5] 6 x
<[18 24 30]> $ 0 swap
<[18 24 30]> $ (+) /
<72> $ .


   ec <expression>: evaluate <expression> as a sequence of
                    ec commands and print the resulting stack.
   ec             : enter interactive (repl) mode.

ec operates as a RPN desk calculator with quotation and vector math functions. Ordinarily, tokens are evaluated from left to right as they're pushed onto the stack. eg.,

   3 4 +

will push 3, then 4, then apply the operation +, which will pop two elements from the stack, add them, and push their sum.

To quote a sequence of tokens, wrap it in parentheses. eg.,

   (3 4 +)

will push a single quotation containing just those three tokens, which can be applied by subsequent commands.

To create a vector, enclose a sequence of numbers or other vectors in square brackets. eg.,

   [3 4]

will create a 1-dimensional vector and push it on the stack.

Vectors can be added to other vectors or individual numbers. eg.,

   [3 4] 2 +

will add 2 to each element of [3 4], resulting in [5 6].

   [3 4] [2 1] +

will add matching elements of vectors, resulting in [5 5].

Vectors can be of arbitrary dimension, but must contain homogeneous data. eg.,

   [[2 1] [0 0]]

is a valid vector (of shape [2 2]), but

   [[2] [0 0]]

is not.

For a full dictionary listing, enter the special command:


To get a description of any word, quote it and use the special command. eg.,

   (i) ?

Will print a description of the apply adverb.


On Arch Linux, install ec via AUR:

yay -S ec

On other systems, install the Janet language, clone this repository and build using jpm:

$ mkdir janet_modules
$ JANET_PATH=janet_modules/ jpm load-lockfile
$ JANET_PATH=janet_modules/ jpm build
$ cp build/ec <somewhere on your path>


EC is built using the Janet language and needs Janet to be compiled. You will use the Janet package manager, jpm, to install it.

#Getting Janet

Install the Janet language. You can download the release here: https://github.com/janet-lang/janet/releases

It's available on Homebrew: https://formulae.brew.sh/formula/janet

And on AUR: https://aur.archlinux.org/packages/janet-lang/

You can read the Janet docsfor more information.

Once you install Janet, you'll have access to the jpm command.

#Installing EC

The EC source is available at https://git.sr.ht/~subsetpark/ec.

You can use jpm to install it, or get it from AUR.


On Linux systems that use the AUR (Arch User Repository), you can install ec:

yay -S ec


#Installing with jpm and sudo

You can also use the jpm package manager. EC requires janet-rl, which uses the libedit library and pkg-config program. Make sure both of those are installed on your system.

Run the following command:

sudo jpm install https://git.sr.ht/~subsetpark/ec

This will download and the EC library with all its dependencies, then compile the ec application and install it. (on my machine, it installs it to /sbin/ec).

#Installing with jpm and without sudo

Clone EC to a working directory and then build it. By default, jpm will install things globally, but you can easily specify a local directory. Here's an example:

code-src/ec [master !]  JANET_PATH=janet_modules jpm load-lockfile
<all the deps get downloaded and compiled...>
code-src/ec [master !]  JANET_PATH=janet_modules/ jpm build       
generating executable c source...
found native janet_modules/_jmod_posix_spawn.so...
found native janet_modules/_sh.so...
found native janet_modules/json.so...
found native janet_modules/moondown.so...
compiling build/ec.c to build/build___ec.o...
linking build/ec...

The ec executable is now in the ./build directory. You move it wherever you like (I move mine to ~/bin/).