Drw

From Esolang
Jump to navigation Jump to search

Drw is a stack-based esolang with turtle output (Text output exists for debugging purposes. There is no way to output other text). Drawing inspiration from uiua and logo, It is meant to be a tool to help children (or other people) begin to think and program in a stack based model. It was created by user:Phidas because they thought it would be kinda cool.

Syntax

Commands

Turtle moving commands

Command Meaning
^
Move the the turtle forward
~
Turn the turtle right
o
Make turns use degrees (the default). If turns already use degrees, push 360(the number of degrees in a circle).
r
Make turns use radians. If turns already use degrees, push τ(the number of radians in a circle).
c
Pops three values ∈[0, 256) or one box with all values ∈[0, 256) and sets the turtle's pen color to that color.
d
Puts the turtle's pen down (the default).
u
Pulls the turtle's pen up.
s
Sets the turtle's pen size (1 by default).

Stack manipulation commands

Command Meaning
.
Duplicate the top value of the stack
:
Swap the top two values of the stack.
p
Pop the top stack value, discarding it.
(
Goes down one in the stack.
)
Goes up one in the stack.
?
Print out the whole stack without popping it. For debugging only.

Math commands

Command Meaning
+-*/%p
Add, subtract, multiply, divide, modulo and power of respectively.
leqS
Log (with base), the constant e, square root and sine respectively.
CfR
Ceiling, floor and round respectively.
=<>
Equal, less than and greater than respectively. Booleans are either 1 or 0.

Box commands

Command Meaning
B
Puts three values in a box, which can only currently be numbers, but implementation of recursive boxes are planned. A box can be treated like any other value on the stack, except it currently doesn't support any arithmetic operations.
U
Unboxes three values
I
Returns 1 if the top value on the stack is a box (not consuming it) and 0 otherwise. Currently unimplemented.

Control structures

Loops

Syntax Meaning
[...]
Repeats the code within it however many times are on top of the stack. Acts as an if statement if passed a boolean.
{...}
Repeats the code within it until the value on the top of the stack at the end of running is 0. Not super useful, but nice to have when you need it.

Functions

Functions are bound using:

<The function's name>_<The function's body>

The functions name may be any one Unicode character that is not a builtin. Functions can be recursive and may take and return any number of arguments.

Comments

Comments are marked using #

examples

square

4[10^90~]

spiral

1 100[.^91~1+]

0 255 0 c # set initial pen color
1 50[ # repeat fifty times
  6[.^60~]2+ # draw a hexagon of the current size on the stack and increase the size 
  .5*255:% 255 0 c # change the current color based on the size on the stack
]

Factorial

⊛_.1>[.1:-⊛*] # calculates the factorial of a number
1⊛
2⊛
3⊛
4⊛
5⊛
6⊛
7⊛
8⊛
9⊛
10⊛

Interpreters and other resources