esolang

Canvas

A stack golfing language for ASCII art, where plain ASCII is always text and every command is full width.

Turing complete: yes · ●●○ moderate

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

Run it

Expected: Hello, World!

The idea

Canvas is a successor to SOGL, a golfing language by the same author. Its values are numbers, strings, arrays and pieces of ASCII art, and many commands treat art as a grid; they join pieces side by side, mirror them or stack them on top of each other.

Read the story

Commands are full-width characters such as + and {, and the digits are full width too, as in 5. That leaves every printable ASCII character for text, so Hello, World! is a string literal and a whole program. At the end the top of the stack is printed.

The machine

CodeDoes
text “text”Push a string; ASCII digits are text too
0-9 APush 0 to 10
+ - × ÷ %Arithmetic; + joins strings, × repeats them
; :Swap, duplicate
{ ... }Loop over 1 to n, the characters or the items, pushing each
╶Push the next input
O o Q qPrint with or without a newline, popping or not

A command that finds too few values on the stack takes the inputs instead.

Example

The loop pushes 1, 2 and 3 in turn; each time : copies it and O prints the copy.
Expected: 1 2 3 3
Expected: ababab

The loop pushes 1, 2 and 3 in turn; each time : copies it and O prints the copy. The 3 left on top prints once more at the end. In the last program × repeats the string three times.

This implementation is a subset, after the JavaScript interpreter in the dzaima/Canvas repository, which TIO runs. It has strings on one line, numbers, arithmetic, loops and output. Everything that builds or changes art, compressed strings and the other commands stop the run with the reason.

Patterns it teaches

  • Code golf: ASCII is text, so a string literal needs no quotes.
  • Stack machines: a short stack is filled from the input.

Try this

  1. Print the numbers 1 to 10.
  2. Read a word and print it five times.
  3. Hard: print the sum of 1 to 100.

Further

Also in Golfing

Write your own in Run Convert a program from Canvas

Implementation

JavaScript interpreter, source and command line

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

Command line

shib run canvas -e '57×'
shib manual canvas

Source

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

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