esolang

COPY WITH @

One 1 to start with. Every other number is a copy of something, counted up or down.

Yayimhere · Turing complete: yes · ●○○ easy · esolangs.org

Tested with 3 known programs · Test method

Run it

Expected: 0

The idea

Yayimhere made COPY WITH @, or CW@, around a stack that starts with a single 1 and has no number literals. To get a new value you copy the top with @ and count it up or down with + and -. Ten commands do everything.

Read the story

The specification argues it is Turing complete through brainfuck with three cells. -@@ makes three zeros, one ↷ moves to the cell on one side and two ↷ to the cell on the other, as the top goes round to the bottom. The braces are brainfuck's brackets.

The machine

CommandDoes
@Copy the top
#Drop the top
+ -Add or take 1 from the top
!Print the top as a number and keep it
;Print the top as a character
?Read a number and push it
{Jump past the matching } if the top is 0
}Jump back to the matching { if the top is not 0
↷Put the top at the bottom

The specification does not say whether ; pops. This implementation pops, as the specification's own @; and {;} suggest. Numbers have no bound.

Example

The truth machine.

The truth machine. On 0 the { jumps past the loop and the last ! prints 0. On 1 the loop prints 1 for ever.

The numeric cat.

Expected: 5

A countdown. A copy of the 1 is counted up to 5, then printed and counted down until it is 0.

Expected: 54321

The looping counter uses :, which is no command, and its long example states no output, so neither is checked.

Patterns it teaches

  • Stack machines: a stack with no literals, where values come from copies.
  • Turing tarpit: ten commands, and three-cell brainfuck inside them.

Further

Stack-based

Write your own in Run Convert a program from COPY WITH @

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: copy-with.

Command line

shib run copy-with -e '?!' --input '5'
shib manual copy-with

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/copy-with.js

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

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