esolang

Electra

You wire it like a circuit. Currents run along cables, split at every junction and die on bare ground.

Turing complete: yes · ●●● hard · esolangs.org

Tested with 3 known programs · Test method

Run it

Expected: Hello World!

The idea

Electra is a two-dimensional language after AsciiDots, in which the instruction pointers act like electric currents. Generators such as > start a current when the program starts. Cables carry it, and where a cable branches the current is copied into every other branch. Each letter that is a part works on memory as a current passes through it, and a current that enters a part from a side the part does not have dies there. So does a current that runs onto a space.

Read the story

Memory is 64 stacks of doubles. All currents share them, and each current carries its own pointer to one of them. A program ends when the last current dies.

The machine

PartDoes
> < ^ vStart a current
- \| / \ + X *Cables; a branch copies the current
} { n UOne-way cables
O I D # EPush 0, add 1, subtract 1, duplicate, pop
A S M Q %Add, subtract, multiply, divide, remainder of the top two
N PPrint a number or a character
@ &Read a number or a character
$ RSwap the top two, reverse the stack
] [ G g L lPass only if the popped top is 0, not 0, above 0, not above 0, below 0, not below 0
( )Pass only if the stack is empty, or not
F B f bMove the stack pointer; f and b carry the top along
~ !Keys that hold currents until another current touches their side
oEnd the program

Every other character is a portal, and portals are Electra's functions. A current that enters a later copy of a character jumps to the first one in the program and remembers where it came from. When it reaches that first one again, it jumps back.

This implementation leaves out what needs files, which is including other files, packages and the five file parts.

Example

Hello World.

Hello World. One generator feeds every column, M multiplies and P prints, and the last P adds a line feed.

The truth machine. Two generators start at once. The upper current reads the number while the lower one is still on its way, so it duplicates the number only once it is there, prints it with N and loops while [ finds it is not 0.

Expected: 0

Comments run between question marks and are blanked out, so the grid keeps its shape. In this implementation & reads one character and P prints it.

Expected: E

The FizzBuzz is 91 lines and does not get far. Its R has to pass the current west, a side the list for R leaves out, so no current gets past R and the program stops after printing its prompt.

Patterns it teaches

Further

Two-dimensional languages

Stack-based

Write your own in Run Convert a program from Electra

Implementation

JavaScript interpreter, source and command line

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

Command line

shib run electra -e '    >@
    
    +->--#N+
    |      |
    |      #
    |      [
    +------+' --input '0'
shib manual electra

Source

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

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

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