esolang

CSL

Command Stack Language. Instructions are not run when they are read; they are stacked up and run later, last one first.

Actuallyallama, 2016 · Turing complete: unknown · ●●○ moderate · esolangs.org

Tested with 5 known programs · Hello World on Try It Online: identical · Test method

Run it

Expected: 4

The idea

Actuallyallama made CSL in 2016. The full name is Command Stack Language (And Also In 2 Dimensions). It has two stacks. One holds numbers, as in any stack language. The other holds instructions.

Read the story

When the pointer crosses an ordinary command such as + or p, nothing happens yet; the command is pushed onto the instruction stack. Only e and E run them, e the top one and E all of them, newest first. So a straight line of code runs backwards. The arrows, the conditional turns and ! act at once.

The machine

CodeWhenDoes
1laterPush 1
D ~ \|laterDuplicate, swap, drop
+ -laterAdd one, take one
& * _laterAdd, multiply, subtract (the top minus the one below)
P p NlaterPrint a number, a character, a newline
$laterStop a running E
e EnowRun the top command, or all of them
?nowPop; if 0 run the top command, else throw it away
> < ^ vnowTurn
{ }nowPop; if 0 turn left, or if not 0 turn right
!nowStop

The grid wraps around at its edges. The only number literal is 1, so the Hello World builds every character from ones, sums and products.

Example

The first line is read as P * D & 1 1, but E runs it from the right, as 1, 1, add, duplicate, multiply, print.
Expected: 2
Expected: 321

The first line is read as P * D & 1 1, but E runs it from the right, as 1, 1, add, duplicate, multiply, print. The third program counts down. ++1E leaves 3 on the stack and v turns down column 4, which stacks D - P D and runs them as duplicate, print, take one, duplicate. } turns right while the copy is not 0, and ^ and < bring the pointer back to v. At 0 it carries on down to !.

Patterns it teaches

Further

Two-dimensional languages

Stack-based

Write your own in Run Convert a program from CSL

Implementation

JavaScript interpreter, source and command line

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

Command line

shib run csl -e 'P*D&11E!'
shib manual csl

Source

Module
langs/tio/ports.js
Interpreter
langs/tio/csl.js

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

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