owned this note
owned this note
Published
Linked with GitHub
# ASCII-art language
## Up next
## Will possibly be implemented
- [ ] `GetMooreWithStartCell` (character `???`)
- [ ] `GetVonNeumannWithStartCell` (character `???`)
## Done
- [ ] `GetCell([x, y])` (character `???`)
- [ ] `GetCells(direction[, length])` (character `???`)
- [ ] `GetAllCells()` (character `???`)
- [ ] `GetMoore` (character `???`)
- [ ] `GetVonNeumann` (character `???`)
Character quota: 191/256
95 ASCII printables plus newline, 10 superscript digits, 24 Greek letters, 8 directional arrows (137 in total), and:
<!-- Letters remaining: EKOQYZ -->
1. Multidirectional print (no move) `P`
2. Rectangle `UR`
3. Box `B`
3. Polygon `G`
4. Fill `¤`
5. Move `M`
6. Pivot left `↶`
7. Pivot right `↷`
8. Jump `J`
9. InputString `S`
10. InputNum `N`
11. Spawn
12. Kill
13. Reflect `‖`
14. Rotate `⟲`
15. Copy `C`
16. For `F`
17. While `W`
18. If `¿`
19. [block start] `«`
20. [block end] `»`
21. Assignment `A`
22. Addition `⁺`
23. Subtraction `⁻`
24. Multiplication `×`
25. Division (integer) `÷`
26. Modulo `﹪`
27. Equals `⁼`
28. Less than `‹`
29. Greater than `›`
30. Logical and `∧`
31. Logical or `∨`
32. Logical not `¬`
33. [escape char: treat next character as part of a literal string, not code] `´`
34. [expression separator--needed for when two numeric or string literals would otherwise run into each other] `¦`
35. String (or list) length `L`
36. String (or list) indexing
37. String (or list) slicing
38. Int->string, string->int `I`
39. List start `⟦`
40. List end `⟧`
41. Define function or macro (details TBD)
42. [extended operation prefix] `U`
43. Eval `V`
44. Dump to stdout `D`
45. Refresh & pause
46. Cycle/chop `…`
Other possible character assignments (not all of these will probably fit, so they will have to be prioritized):
- Unary negation (Done)
- Increment
- Decrement
- Exponentiation (Done)
- Bitwise operators
- Absolute value
- String reverse
- Count occurrences of substring (Done)
- Find index/indices of substring (Done)
- Uppercase/lowercase (Done)
## Literals
- Integers
- Strings
- Lists
- Dictionaries
- Regex?
## Data Types
- Numeric (just integers, for now)
- String
- List
- Dictionary?
- Function/macro/code block?
- Regex?
## Functions and Statements
### Output and Movement
- [x] `Print([direction, ]string)`
- [x] `Print([direction, ]length)`
- [x] `Rectangle(height, width)`
- [x] `Box(height, width, character)`
- [x] `Polygon(direction, length{, direction, length}, char)`
- [x] `Polygon({direction, }length, char)`
- [x] `Move([length, ]direction)`
- [x] `PivotLeft([turns])`
- [x] `PivotRight([turns])`
- [x] `Jump(x, y)`
**Note:** All `Print` overloads also apply to the `MultiPrint` command, which takes 1 or more direction arguments and does not move the cursor to the end of the output. Multiprint also accepts the ASCII characters `+x*` as directions, indicating "all horizontal & vertical directions," "all diagonal directions," and "all 8 directions" respectively.
### Cursor Management
<!-- Would these make more sense merged into a function-call concept? That would allow reusability, for one thing. -->
- [ ] `Spawn()`
- [ ] `Kill()`
### Input
- [ ] `ReadAll()`
- [x] `ReadString` (acts as `ReadLine` in prompt mode)
- [x] `ReadNumber()`
- [ ] `ReadChars([length])` (defaults to 1)
- [ ] `ReadFromCanvas([x, y][,flags])`
- [ ] `ReadFromCanvas(direction[, length])`
- [ ] `GetAllCells()`
### High-Level Canvas Operations
*(We need to define exactly what `Rotate` does with copying, and what the most recent selection is.)*
- [x] `Reflect(direction)`
- [x] `Rotate(number)`
- [x] `ReflectCopy(direction)`
- [ ] `RotateCopy(number)`
- [x] `ReflectOverlap(direction)`
- [ ] `RotateOverlap(number)`
- [x] `Copy(delta_x, delta_y)`
## Control Flow
- [x] `For <iterable> <body>`
- [ ] `For <body>` (This implicitly iterates over the next input)
- [x] `While <condition> <body>`
- [ ] `If <cond> <if_true> <if_false>`
Blocks can be surrounded by `«` and `»`, mandatory if the block consists of multiple statements, any needed `»` are autocompleted at the end of the program.
## List functions
*(Do we need all of these?)*
- [ ] `Map(body)`
- [ ] `Some(body)`
- [ ] `Every(body)`
## Overloads
- `Print`
- [ ] Endpoints only
- `Multiprint`
- [ ] Fill
- [ ] Rhombus
- [ ] Endpoints only
- `Copy`, `Reflect`, `Rotate`
- [x] Most recently printed only
- `Reflect`, `Rotate`
- [ ] Flip characters
- [x] Copy
- [x] Copy with overlap
- `Polygon`
- [ ] Do not fill
- `Jump`, `Copy`, `ReadFromCanvas`
- [ ] Absolute coordinates (default is relative)
- `ReadFromCanvas`
- [ ] Von Neumann neighborhood
- [ ] Moore neighborhood (both return list)
## Questions
- [ ] Should anchor point or no anchor point be default for `Rotate` and its variations?
- [ ] What does `For` do with a negative argument (say, -3)?
- Loop over 0, -1, -2
- [ ] We should add it [here](http://meta.codegolf.stackexchange.com/questions/6918/what-programming-languages-have-been-created-by-ppcg-users) sometime
- [ ] What should happen when RotateCopy is passed an odd number of rotations (currently errors)?
- If there isn't an obvious thing it should do, we can leave it as an error for the time being
- [ ] Should we have a 2-character builtin for image input?
- Very low priority, I was thinking this would be included mostly for fun, plus kinda relevant
- [ ] Do we need things like `Crop`? Otherwise, should we give it a long command character instead?
- I think it will be useful. We can give it a 2-char command, and if we end up using it a lot we can promote it to a 1-char command.
- Any similar commands you think are useful?
- [ ] Should we have a builtin for the Bresenham algorithm?
- Eventually, not a priority.
## Paradigm
Imperative, with prefix operators.
## Codepage
Characters include:
- Printable ASCII characters `` !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ `` and space
- Newline/`¶` (same character code)
- Superscript numerals `⁰¹²³⁴⁵⁶⁷⁸⁹` <!-- Note: I replaced Jelly's ° (which is actually U+00B0 DEGREE SIGN) with ⁰ (U+2070 SUPERSCRIPT ZERO). -->
- Full-width capital letters `ABCDEFGHIJKLMNOPQRSTUVWXYZ` (and possibly lowercase `abcdefghijklmnopqrstuvwxyz`)
- Greek lowercase letters `αβγδεζηθικλμνξπρσςτυφχψω` <!-- Leaving out omicron because it's indistinguishable from o -->
- Arrows `←↑→↓↖↗↘↙↶↷⟲`
- Brackets `⟦⟧⦃⦄«»`
- Arithmetic operators `⁺⁻×÷﹪`
- Comparison operators `⁼‹›` (and maybe `≠≤≥`)
- Logic operators `∧∨¬`
- Other `¿…‽‖´·¤¦`
<sub>(95 + 1 + 10 + 26 + 24 + 11 + 6 + 5 + 3 + 3 + 8 = 192/256)</sub>
## Syntax
### Tokens
- Any run of printable ASCII and/or `´`-escaped characters: literal string
- Any run of (superscript) digits: literal integer
- Any lowercase Greek letter: variable
- Any single other character: command, operator, or separator
- There may be one or more characters designated as combining marks, which make for some two-character commands/operators
### Grammar
In slightly modified [BNF](https://en.wikipedia.org/wiki/Backus%E2%80%93Naur_Form):
Program ::= Command Program | ""
Command ::= Print | MultiPrint | Polygon | Move | Pivot | Jump
| Reflect | Copy | For | While | If | Assign | Fill
| SetBackgrd | Rotate | Rectangle | Dump | Refresh | ...
Print ::= Arrow Expr | Expr
MultiPrint ::= "P" MultiDirec Expr
MultiDirec ::= "+" Arrows | "x" Arrows | "*" Arrows | Arrow Arrows
Arrows ::= Arrow Arrows | ""
Arrow ::= "←" | "↑" | "→" | "↓" | "↖" | "↗" | "↘" | "↙"
Polygon ::= "G" Side Sides Expr | "G" Arrows Expr Expr
Sides ::= Side Sides | ""
Side ::= Arrow Expr
Move ::= "M" Expr Arrow | "M" Arrow
Pivot ::= "↶" Expr | "↶" | "↷" Expr | "↷"
Reflect ::= "‖" Arrow
Rotate ::= "⟲" Expr
Jump ::= "J" Expr Expr
Copy ::= "C" Expr Expr
For ::= "F" Expr Body
While ::= "W" Expr Body
If ::= "¿" Expr Body Body
Body ::= "«" Program "»" | Command
Assign ::= "A" <name> Expr
Fill ::= "¤" Expr
SetBackgrd ::= "UB" Expr
Rectangle ::= "R" Expr Expr Expr
Dump ::= "D"
Refresh ::= <...>
Expr ::= Niladic | Monadic Expr | Dyadic Expr Expr | <name>
| Input | Value Sep
Niladic ::= "N" | "S" | "‽" | ...
Monadic ::= "⁻" | "L" | "¬" | "I" | "‽" | "V" | ...
Dyadic ::= "⁺" | "⁻" | "×" | "÷" | "﹪" | "⁼" | "‹" | "›" | "∧" | "∨"
| "…"
Input ::= "N" <name> | "S" <name>
Value ::= <strliteral> | <intliteral> | List
Sep ::= "¦" | ""
List ::= "⟦" Exprs "⟧"
Exprs ::= Expr Exprs | ""
## Example PPCG challenges
*Selection criteria: require a diversity of techniques, relatively simple, popular*
*Note: Our language will not necessarily match the current best score on all of these, but it should for some, and it should be competitive for all of them.*
- [Do you want to code a snowman?](http://codegolf.stackexchange.com/q/49671/16766)
- Best existing score: CJam, 125
- Techniques: string/char input, literal strings, conditionals
- [It's my birthday](http://codegolf.stackexchange.com/q/57277/16766)
- Best existing score: Pyth, 67
- Techniques: numeric input, pattern repetition, lines of same character, conditionals
- Best solution, 69 (3% longer, can be shorter if for with negative argument does nothing): `NβA-~-¶θ¿‹β⁰F³θ¿β«θFβ⁺-~-|$¶θ»↓Congratulations on your new baby! :D⟲⁶`
- [Seven-slash display](http://codegolf.stackexchange.com/q/51445/16766)
- Best existing score: CJam, 62
- Techniques: string/char input, conditionals, non-obvious cursor management
- [Christmas tree of height N](http://codegolf.stackexchange.com/q/4244/16766)
- Best existing score: J, 24
- Techniques: numeric input, math, polygon
- Best solution, 9 (54% shorter): `G↗↘←N*M↓*`
- **Submitted to PPCG**
- [Turtles all the way down](http://codegolf.stackexchange.com/q/87614/16766)
- Best existing score: 05AB1E, 45
- Techniques: numeric input, looping, lines of same character, math (for alternating which side the head goes on)
- [Telescopic parentheses](http://codegolf.stackexchange.com/q/49042/16766)
- Best existing score: CJam, 15
- Techniques: string input, loops, non-obvious cursor management
- Best solution, 14 (6% shorter): `FS¿⁼ι(«(↓»«M↑)`
- [Bake a slice of pi](http://codegolf.stackexchange.com/q/93615/16766)
- Best existing score: MATL, 67
- Note: I doubt any language can touch this without a builtin to calculate pi
- Shortest solution that hardcodes the number: ///, 127
- Techniques: literal strings, lines of same character, pattern repetition
- Best solution, 71 (6% longer): `×⁶()↙↓¹⁰↖↖¹⁰↓↓²↘⁸M↑__↖←¤:↗¤3.141592653589793238462643383279502884197169`
- **Submitted to PPCG**
- [Another brick in the wall](http://codegolf.stackexchange.com/q/90022/16766)
- Best existing score: Pyth, 27
- Techniques: numeric input, lines of same character (or rectangle), pattern repetition, trimming?
- [Abelian sandpile](http://codegolf.stackexchange.com/q/92251/16766)
- Best existing score: MATL, 43 <sub>*(42 for graphical output)*</sub>
- Techniques: numeric input, read canvas cells, math, non-obvious cursor management, recursion??
- [Quack the angry duck](http://codegolf.stackexchange.com/q/74212/16766)
- Best existing score: Cinnamon Gum, 76
- Techniques: numeric input, literal strings, conditionals, pattern repetition, um...
- [Golf your language's identicon](http://codegolf.stackexchange.com/q/49566/16766)
- Best existing score: CJam, 71
- Techniques: polygon (or loops + lines of same character), reflection, rotation <!-- We may need Bresenham for this -->
- [Generate wordenticons](http://codegolf.stackexchange.com/q/80736/16766)
- Best existing score: MATL, 15
- Techniques: string input, loops, string comparison, reflection
- [Enlarge ASCII art](http://codegolf.stackexchange.com/q/19450/16766)
- Best existing score: APL, 7
- Techniques: numeric input, ASCII-art input? or string input + lists, polygon/rectangle
- [ASCII double helix](http://codegolf.stackexchange.com/q/49962/16766)
- Best existing score: CJam, 50
- Techniques: numeric input, pattern repetition, rotation? (would need flag to transliterate characters appropriately)
- Best solution, 71 (badly golfed, need to rewrite because RotateTransform finally exists): `Nβ¿›β⁰«↶² O¶\ /¶/ \¶F⁻β¹« /¶\ /¶/ \¶» O»« O¶/ \¶\ /¶F⁻¹β« \¶/ \¶\ /¶» O`
- [Shifty eyes shifting I's](http://codegolf.stackexchange.com/q/74719/16766)
- Best existing score: CJam, 33
- Techniques: string input, conditionals, read canvas cells, non-obvious cursor management (keep two cursors? `Find` operation?)
- [Yarr! A map to the hidden treasure](http://codegolf.stackexchange.com/q/54301/16766)
- Best existing score: Ruby, 178
- Techniques: string input interleaved with numeric input, conditionals, lines of same character
- [Draw an Empty Scrabble Board](http://codegolf.stackexchange.com/questions/92055/draw-an-empty-scrabble-board)
- Best existing score: MATL, 52
- Techniques: Reflection with copy, printing in a certain direction
- Best solution, 34 (36% shorter): `T↑↑↘tdd↗→→↖XdtDDDD↓T..d‖O⟦↗→↓⟧UB.`
- **Submitted to PPCG**