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
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
| Code | When | Does |
|---|---|---|
1 | later | Push 1 |
D ~ \| | later | Duplicate, swap, drop |
+ - | later | Add one, take one |
& * _ | later | Add, multiply, subtract (the top minus the one below) |
P p N | later | Print a number, a character, a newline |
$ | later | Stop a running E |
e E | now | Run the top command, or all of them |
? | now | Pop; if 0 run the top command, else throw it away |
> < ^ v | now | Turn |
{ } | now | Pop; if 0 turn left, or if not 0 turn right |
! | now | Stop |
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.
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
- Two-dimensional control flow: loops are drawn as paths on the grid.
- Stack machines: with a second stack for the program itself, which runs in reverse.
See also
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 cslSource
- 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