-
Notifications
You must be signed in to change notification settings - Fork 1
Stack Notation
Dev Note: I am not too happy with the current notation, so this may be subject to change in the future. I am also thinking about backing the notation with a proper type-checker implementation.
In the commands reference, you may notice that each command has
a Stack:
entry. These entries informally describe how the command affects the
stack. Take for example the following signature for swap
:
a b -> b a
Here, b
is the top of the stack and a
is second from top of the stack. ->
separates the "before" and "after" parts of the signature.
Another signature, this time for roll
:
(a @ n) b* (n >NUM) -> b* a
Looks kinda gnarly right? Let's break it down.
-
n >NUM
means thatn
is implicitly converted toNUM
at the argument level. -
a @ n
means thata
isn
positions from the top of the stack (0-indexed). Son = 0
is the top of the stack,n = 1
is second from the top of the stack,n = 2
is third from the top of the stack, etc. -
b*
means that 0 or more items may exist at that location in the stack.
Other notation to know:
-
a'
means thata
vectorizes -
SEQ[NUM*]
means aSEQ
containing 0 or moreNUM
s -
MAP[(STR => NUM)*]
means aMAP
containingSTR
keys andNUM
values -
a.x
means a valuex
that is an item ina
-
a | b
means "a
orb
." -
f: x -> _
means a valuef
that evaluates using the stack signaturex -> _
.
Made with ❤️ by Ben Pang (@molarmanful).