#### [Spec](../)
- [Data types](../types)
- **Operators**
- [Encoding](../encoding)
**Please note:** This spec is a draft; any detail may change without warning.
A list of what has been implemented can be found [here](https://github.com/ETHproductions/crayon/blob/master/info.txt).
### Operators
Click on a category or operator to expand it.
Key:
- `N` - Number
- `C` - Char (acts like `S` unless otherwise specified)
- `S` - String
- `A` - Array
- `R` - Regex
- `O` - Any type
Expand all
-
Canvas manipulation
- `→` - points the cursor E.
- `↘` - points the cursor SE.
- `↓` - points the cursor S.
- `↙` - points the cursor SW.
- `←` - points the cursor W.
- `↖` - points the cursor NW.
- `↑` - points the cursor N.
- `↗` - points the cursor NE.
- `⤸` - turns the cursor clockwise by 45 degrees.
- `⤵` - turns the cursor clockwise by 90 degrees.
- `↷` - turns the cursor clockwise by 135 degrees.
- `⟲` - turns the cursor by 180 degrees.
- `↶` - turns the cursor counter-clockwise by 135 degrees.
- `⤷` - turns the cursor counter-clockwise by 90 degrees.
- `⤹` - turns the cursor counter-clockwise by 45 degrees.
- `e` - moves the cursor E by 1 unit.
- `s` - moves the cursor S by 1 unit.
- `w` - moves the cursor W by 1 unit.
- `n` - moves the cursor N by 1 unit.
- `f` - moves the cursor forward by 1 unit.
- `F` - pops `N` and moves the cursor forward by `N`.
- `q` - draws the top item at the cursor and moves the cursor to the end of the drawn string.
- `Q` - like `q`, but removes the item from the stack.
-
Input
- `T` - inputs the next space-separated token.
- `L` - inputs the next line.
- `Z` - inputs a multi-line string, stopping at double newline or EOF.
- `E` - inputs all remaining input.
-
Control flow
- `z` - if TOS is truthy...
- `!` - if TOS is falsy...
- `=` - if top 2 items are equal...
- `<` - if top item is less than next item...
- `>` - if top item is greater than next item...
- `?` - delay execution of the previous conditional until here.
- `{` - else...
- `O` - for each item `I` and index `i` in TOS...
`I` is pushed before each iteration.
For numbers, loops through `[0..n)`.
If already in a loop, the outer loop uses `J` and `j`.
- `W` - while TOS is truthy...
- `}` - end-if/end-loop. Implicit at end of program.
-
Stack manipulation
- `[` - push an array and use it as the stack.
- `]` - exit array and push to stack. If not in array, wraps the entire stack in an array.
- `~` - use top array as the stack.
- `\` - swap top two items.
- `@` - pull up the third item.
- `:` - duplicate top item.
- `;` - remove top item.
- `.;` - push last removed item.
- `,` - duplicate from below?
- `l` - pull up `n`th item.
- `#`? - push the length of the stack.
-
Unary operations
-
`N`
- `N` - no-op.
- `C` - convert to charcode.
- `S` - attempt to convert to number.
- `A` - sum.
-
`S`
- `N/C` - convert to string.
- `S` - no-op.
- `A` - join with (newline? empty string?).
-
`A`
- `N` - range; (`[0...N-1]`? `[1...N]`?)
- `C` - ???
- `S` - convert to an array of chars.
- `A` - no-op.
-
`(`
- `N/C` - decrement. `a-1`
- `S/A` - shift; remove first char/item and place on stack.
-
`)`
- `N/C` - increment. `a+1`
- `S/A` - pop; remove last char/item and place on stack.
-
`_`
- `N` - negate. `-a`
- `S/A` - reverse.
-
`~`
- `N` - bitwise NOT. `-a`
- `S` - eval.
- `A` - enter.
-
`.~`
- `N` - ???
- `S/A` - uniquify.
-
`F`
- `N` - move the cursor forward by `N`.
- `S` - ???
- `A` - flatten.
-
`l`
- `N` - bring up the `n`th item.
- `S/A` - pushes length. `"abc"l` → `"abc" 3`
-
`X`
- `N` - move to `x`.
- `S/A` - spread onto the stack.
-
`x`
- `N` - move by `x`.
- `S` - ???
- `A` - join with the empty string.
-
`Y`
- `N` - move to `y`.
- `S` - convert to array of charcodes.
- `A` - convert from array of charcodes.
-
`y`
- `N` - move by `y`.
- `S` - ???
- `A` - ???
-
Binary operations
-
`+`
- `NN` - adds two numbers. `a+b`
- `NC` - adds `a` to the charcode of `b`. ``3`a+ -> `d``
- `NS` - prepends the number to the string. `a+b`
- `SN` - appends the number to the string. `a+b`
- `SS` - concatenates the strings. `a+b`
- `AA` - concatenates the arrays. `a.concat(b)`
- `AO` - appends the item to the array. `a.push(b)`
- `OA` - prepends the item to the array. `b.unshift(a)`
-
`-`
- `NN` - subtracts two numbers. `a-b`
- `NC` - subtracts `a` from the charcode of `b`. ``3`d-`` → `` `a``
- `NS` - slice; if `n` is negative, keep only the last `n` chars of `s`; else, remove the first `n` chars of `s`.
- `SN` - slice; if `n` is negative, keep only the first `n` chars of `s`; else, remove the last `n` chars of `s`.
- `NA` - same as `NS`.
- `AN` - same as `SN`.
- `SS` - removes instances of `b` from `a`.
- `SR` - removes matches of `r` from `s`.
- `AA` - setwise subtraction; remove all items in `b` from `a`.
- `AO` - remove all instances of the item from the array.
-
`*`
- `NN` - multiplies two numbers. `a*b`
- `NS` - repeats `s` `n` times. `s.repeat(n)`
- `NA` - repeats `a` `n` times.
- `SS` - setwise addition? (concat, sort?, uniquify)
- `SR` - find all matches of `r` in `s`.
- `AA` - setwise addition? (concat, sort?, uniquify)
- `SA` - joins `a` with `s`. `a.join(s)`
-
`/`
- `NN` - divides two numbers. `a/b`
- `NS` - splits `s` into groups of `n` chars. `s.match(RegExp(".{1,"+n+"}","g")`
- `NA` - splits `a` into groups of `n` items.
- `SS` - splits `a` at occurances of `b`. `a.split(b)`
- `SR` - splits `s` at matches of `r`. `s.split(r)`
- `AA` - pairs arrays. `[0 1 2][3 4 5]/` → `[[0,3],[1,4],[2,5]]`
-
`%`
- `NN` - modulo two numbers. Always returns a positive number. `(a%b+b)%b`
- `NS` - unriffles `s` into `n` strings. `"abcde"2%` → `["ace""bd"]`
- `NA` - unriffles `s` into `n` arrays. `[1 2 3 4 5]2%` → `[[1 3 5][2 4]]`
- `SS` - riffles `a` with `b`. `"abc""123"% -> "a1b2c3"`
- `SR` - splits `s` into matches and non-matches of `r`. ``"a1b2cd"'`d'%`` → `["a""1""b""2""cd"]`
- `AA` - riffles arrays. `[0 1 2][3 4 5]%` → `[0 3 1 4 2 5]`
-
`&`
- `NN` - binary AND. `a&b`
- `NS` - ???
- `NA` - filter? `[1 2 3 2]2&` → `[2 2]`
- `SS` - setwise intersection of `a` and `b`. `"bar""abc"&` → `"ba"`
- `SR` - ???
- `AA` - setwise intersection of `a` and `b`.
-
`|`
- `NN` - binary OR. `a|b`
- `NS` - ???
- `NA` - ???
- `SS` - setwise addition of `a` and `b`. `"bar""abc"|` → `"barc"`
- `SR` - ???
- `AA` - setwise addition of `a` and `b`.
-
`^`
- `NN` - binary XOR. `a^b`
- `NS` - ???
- `NA` - ???
- `SS` - setwise XOR of `a` and `b`. `"bar""abc"^` → `"rc"`
- `SR` - ???
- `AA` - setwise XOR of `a` and `b`.
-
`g`
- `NN` - power. `a**b`
- `NS` - get char at index `n` in `s`.
- `NA` - get item at index `n` in `a`.
- `SS` - ???
- `SR` - ???
- `AA` - ???
-
`C`
- `NN` - move crayon to `x`, `y`.
- `AO` - index.
- `SO` - index.
-
`c`
- `NN` - move crayon by `x`, `y`.
- `AO` - last index.
- `SO` - last index.
-
`B`
- `NN` - convert `a` to array of base-`b` digits.
- `NS` - convert `s` to array of base-`n` digits?
- `NA` - convert `a` to base-`n` string?
- `SS` - ???
- `SR` - ???
- `AA` - ???
-
`b`
- `NN` - convert `a` to string of base-`b` digits, using the alphabet `0-9a-zA-Z$_`.
- `NS` - convert `s` from string of base-`n` digits.
- `NA` - convert `a` from array of base-`n` digits.
- `SS` - ???
- `SR` - ???
- `AA` - ???
-
Unassigned tasks
-
`N`
- convert to char
- range (inverse of `A` command, either `[0...N-1]` or `[1...N]`)
-
`S`
-
`A`
- transpose
- rotate
- sort
- self-riffle (`[1 2 3 4 5 6]` → `[1 3 5 2 4 6]`