Carriage
The program is the function, and the program is also the stack it is applied to.
Chris Pressey, 2012 · Turing complete: unknown · ●●● hard · esolangs.org
Tested with 3 known programs · Test method
Run it
The idea
Chris Pressey designed Carriage in November 2012 as a pure concatenative language, where joining two programs is exactly composing their functions. There are no quoted programs. Instead the whole program is read twice. Read as code it is a function from stacks to stacks; read as data it is the starting stack, one instruction symbol per element. To make a subroutine, @ slices a run of symbols out of that stack and turns it into a function, and ! applies it.
The machine
| Symbol | Does |
|---|---|
1 | Push 1 |
~ | Pop n, copy the element n deep |
\ $ | Swap; pop |
# | Push the size of the stack |
+ - | Pop a, pop b, push a + b or b − a |
@ | Pop k and p, push the function of the k symbols from position p, counted from the bottom |
! | Pop a function and apply it |
Anything the specification does not allow, such as picking an instruction symbol, makes the program explode. Carriage has no input or output. This implementation prints the stack the program ends with, bottom first, the way the specification writes it.
Example
In the second program 11+$ makes 2 and drops it, so the code does nothing, but as data its symbols at…
In the second program 11+$ makes 2 and drops it, so the code does nothing, but as data its symbols at positions 1 and 2 are 1+. Then 11+111+@ slices those two symbols into a function that adds one, and ! applies it to the 2 below it.
Further
Ideas it shows
See also
Stack-based
Write your own in Run Convert a program from Carriage
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: carriage.
Command line
shib run carriage -e '$$$'shib manual carriageSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/carriage.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org