Skip to content

Function Reference

Alex Craik edited this page Jan 2, 2020 · 11 revisions

This document describes all of the functions in Ahead.

Glossary

There are a few terms in this reference that may need to be defined. The terms are used as shorthand so the descriptions do not become long and repetitive (bad things for tables to be.)

Bounce
When the head bounces, it changes direction such that it begins traveling in the opposite direction on the next move.
True
The value popped from the top of the stack is nonzero. Thus, false is a zero value.
nth-of-stack
The top-of-stack is the value last pushed to the stack; the second-of-stack is the value under that, and so on.

Additionally, if a function ever checks the stack, it will remove the value it is checking. The exception, of course, is the duplication function.

Movement

Character Description
^ Go North.
v Go South.
< Go West.
> Go East.
L Turn left by 90 degrees.
R Turn right by 90 degrees.
l Turn left by 45 degrees.
r Turn right by 45 degrees.
n If true, go North.
s If true, go South.
w If true, go West.
e If true, go East.
b Bounce.
? If true, bounce.
x Go in a random direction.
X Go in a random cardinal direction.
| If true, go North; else, go South.
_ If true, go West; else, go East.
~ Toggle Floating state.
h Turn the head by top.
H Set the head’s directio to top.
j Skip the next cell.

Math and Data

Character Description
+ Add the top-of-stack to the second-of-stack.
- Subtract the top-of-stack from the second-of-stack.
* Multiply the top-of-stack by the second-of-stack.
/ Divide the second-of-stack by the top-of-stack.
% Find the remainder of division (as defined above).
; Find the modulo of second by top.
m Negate the top-of-stack.
a Find the absolute value of the top-of-stack.
p Raise the second-of-stack to the top-of-stackth power.
E Pop two values and push all in that range, inclusive.
= Push 1 if top two values are equal, else 0.
! If top-of-stack is 0, make it 1; else, make it 0.
) Push 1 if second is greater than top, else 0.
( Push 1 if second is less than top, else 0.
[ Find the lesser of the top two stack items.
] Find the greater of the top two stack items.
C Increment register.
c Decrement register.
\ Swap the top two stack items.

Stack Manipulation

Character Description
: Duplicate the top-of-stack.
$ Pop the top-of-stack and discard it.
d Push the number of stack items to the stack.
D Clear all items off the stack.
& Move the top-of-stack to the register.
t Copy the register and push it to the stack.
{ Take the last stack item and put it on top.
} Take the top stack item and move it to the end.
u Reverse the contents of the stack.
U Reverse stack contents up to the first 0.

Input/Output

Character Description
i Read a character from standard in and push it.
I Parse a number from standard in and push it.
o Print the top-of-stack to standard out as a character.
O Print the top-of-stack to standard out as a number.
S Read all chars from stdin until empty.
W Print characters off the stack to standard out until a 0.

Misc/Special

Character Description
N Push a linefeed to the stack.
Toggle String state.
k Execute the next cell top-of-stack times.
K Repeat the next cell until the stack has one item.
Push the character in the next cell to the stack.
# Wall.
@ Kill the head and terminate the program.

Featured Links

Ahead Homepage

PPCG

Befunge

><>

Clone this wiki locally