esolang

pith

Three stacks, and the one in control holds vectors. Every number comes out as the length of an arrow.

ZippyMagician, 2021 · Turing complete: yes · ●●○ moderate · esolangs.org

Tested with 6 known programs · Test method

Run it

Expected: 5

The idea

ZippyMagician made pith in 2021, a language themed around vectors. A vector is a pair of 64-bit floats. The control stack N holds vectors, and two plain stacks, I and J, take the left and the right part when a vector is split. Printing and testing both use the magnitude, the length of the vector, so <3, 4> prints as 5.

Read the story

A program runs line by line. Its one conditional jump pops a vector and goes to a line by number when the vector has length 0. Every character that is not a command is ignored, so comments need no marker.

The machine

CommandDoes
:M :[A, B]Push <M, 0> or <A, B> to N
* =Split the top of N into I and J; join the tops of I and J into N
&XPush X more copies of the top of N
+ -Add or subtract the top two vectors
. @ %Dot product, sign of the length, absolute parts, pushed to I and J
/ \ ^ vMove a number from I to J or back; drop the top of I or J
\| _Pop and print the length as a character or as a number
#XRead X numbers, each as <M, 0>
,XPop; if the length is 0, jump to line X, counted from 0
< > !> goes back to its <; ! halts
$Send what . and @ push to I only, then J only, then both again

Example

<3, 4> is 5 long.

<3, 4> is 5 long.

The Hello World pushes each letter as a vector along the x axis and prints its length. &2 and & leave spare copies of l and o lower on N, and the second | after W and after r prints them.

Expected: Hello, World!

The division subtracts the divisor until the vector is 0, keeps a count on I and jumps to line 1 to print it. It works only when the quotient is whole.

Expected: 3

The cat reads numbers and prints them until it reads 0.

Expected: 7

Patterns it teaches

  • Stack machines: three stacks, one of vectors and two of numbers.
  • Counter machines: the specification proves pith Turing complete by turning each line of a Minsky machine into a line of pith.

Further

Stack-based

Write your own in Run Convert a program from pith

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: pith.

Command line

shib run pith -e '<#&,1_>
!' --input '7 0'
shib manual pith

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/pith.js

Docs: Kernel instructions · The .shib format · Command line · Adding a language

Source esolangs.org (CC0) · Edit on esolangs.org