Skip to content

The Basics

dzaima edited this page Apr 7, 2018 · 3 revisions

Like in Charcoal, every ASCII character (plus and ŗ) in Canvas are a part of strings. are newlines and each ŗ gets replaced by an item from the stack. So Hello, ¶ŗ! would output Hello, \n, followed by the first input and then !. In case you need to push two strings one after the other, you can separate them with .

Otherwise, everything is a function. Mostly everything is a single character, but there are some multibyte commands (most notably the palindromization stuff).

Execution is left-to-right, except when the code is in a loop or similar structure.
If there isn't an item on the stack to pop for a function, it'll take the next input. The inputs are cyclic, so PPP with two given inputs will output the 1st, then the 2nd and then the 1st again.
A simple program to add 5 to the input is 5+ - pushes 5, and then adds that and the 1st input.

The console, while in dev mode, contains the stack history.

Loop Structures

Canvas has 3 loop starters: , and , and 2 "others": and .

For the first two, they end with either or . is the default ending (if ommited at the end).
is "iterate over" - it pops, and executes the code until the matching end, each time pushing the current item. For numbers it creates a range [1-n]
currently only works on numbers (because I haven't decided what should it do for strings/arrays), and it just repeats the following code, without pushing anything. an ending of does nothing, while each iteration collects the items left from the start on the current iteration till the end (popping them), and collects the result in an array. Note that the resulting array will have the separate items on the stack as separate items in the array. Here's an example of it working - it results to [1, ",", 2, ",", 3, ","]: 5R - range 1..5, - for each, push the item, , - push ,, - collect to array.

is if or (not implemented yet!) if-else / number switch if ending with , pops a value, and if it's truthy, runs the following code, otherwise just skips it. This example subtracts 5 from the input, if it's larger than 5. Note that the can be removed here. is "if not" / switch, but it's also not implemented.

Superscripts & Subprograms

Superscripts ¹-⁹ contain potentially context-specific stuff. They are initially some numbers (defaults available in the docs), but soon are overridden.

Each line before the last is a subprogram. The last line is where the execution starts. For each line, a superscript is set to a command to execute it. More precisely, the main program becomes (hence why it has no other default), the line before that is , then , etc.
After those, the 1st input becomes the next biggest superscript, and so on.
Loop stuff is stored (and left there after finishing) from ¹ to bigger ones. They are loop type dependant, but usually the depth of the loop'th superscript is the iterated item / counter and the next may be the counter (if it isn't in the previous).

Clone this wiki locally