NEW +
Trace
Output
Help

Language Documentation

Github Other systems

A stack-based language. Words consume values from the stack and push results back.

  • Case of words does not count, dup and DUP are the same.
  • The notation ( before -- after ) shows a word's effect on the stack.

Editor

During typing, following shortcuts are working.
CTRL+S
Run code.
CTRL+I
Show trace tab.
CTRL+O
Show output tab.
CTRL+H
Show help tab.

Comments

(...)
Block scoped comment.
\ ...
Comment to the end of the line.

Numeric Operations

+
( n1 n2 -- n1+n2 )
Adds the top two numbers.
-
( n1 n2 -- n1-n2 )
Subtracts the top number from the second.
*
( n1 n2 -- n1*n2 )
Multiplies the top two numbers.
/
( n1 n2 -- n1/n2 )
Divides the second number by the top one.
= > <
( n1 n2 -- bool )
Pushes true or false after comparison.

String Operations

'+
( s1 s2 -- s1s2 )
Concatenates two strings.
'*
( s n -- s*n )
Repeats a string n times.
'=
( s1 s2 -- s1=s2 )
String comparison, returns boolean.
'LEN
( s -- n )
String length, returns number.
'I
( s n -- s[n] )
Char at index, returns string.

Boolean Logic

NOT
( bool -- !bool )
Inverts a boolean value.

Stack Manipulation

DUP
( a -- a a )
Duplicates the top stack item.
DROP
( a -- )
Removes the top stack item.
SWAP
( a b -- b a )
Swaps the top two stack items.
OVER
( a b -- a b a )
Copies the second item to the top.
5 9 over over > .s

--- PRINT-STACK ---
[0]: false
[1]: 9
[2]: 5
---
PICK
( .. xn..x0 n -- ..xn..x0 xn )
Copies the n-th item (0-indexed) to the top.
20 15 10 .s
(
[0]: 10
[1]: 15
[2]: 20 <---
)
2 pick .s
(
[0]: 20 <---
[1]: 10
[2]: 15
[3]: 20
)
EMPTY?
( -- bool )
Pushes boolean if the stack is empty.
STACK-LEN
( -- len )
Pushes the current stack depth.

Printing & Output

.
( a -- )
Pops and prints the top value.
.p or PRINT
( a -- a )
Prints the top value without affecting stack.
.s or PRINT-STACK
( -- )
Prints the entire stack non-destructively.

Definitions & Control Flow

: <name> ... ;
Defines a new word.
: SQUARE DUP * ;
5 SQUARE . ( prints 25 )
<cond> IF ... THEN
<cond> IF ... ELSE ... THEN
Conditional branching.
5 3 > IF "Bigger" . THEN
\OUTPUT: "Bigger"

3 5 > IF "Bigger" ELSE "Lesser" THEN .
\OUTPUT: "Lesser"
BEGIN ... <cond> UNTIL
Loops until the condition is true.
( Counts 0 to 4 )
0
BEGIN
  DUP . 1 +
  DUP 5 =
UNTIL

\OUTPUT: 0 1 2 3 4