Stack

From WikiManual
Revision as of 06:17, 24 June 2005 by Ulciscor (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

The Stack

Overview The basic principle is that everything is done passing through a last-in first-out stack. It's like a stack of dishes: you can take or put a dish only from the top of the stack, all others are inaccessible. The language's instructions work on the data that is on the top of the stack, removing them and putting the results in their place.


For example, to sum two numbers, you should put them in the stack, and then invoke the sum instruction. It will remove the two numbers, calculate the sum, and put the result on top of the stack.

It may seem complicated, but's not. For instance, where you usually write

b+c=a

now you should write

b c add

The add instruction removed b and c from the stack and replaced it with the sum of the two, a.

Just like a pile of dishes can get too big, when the stack fills up with numbers it will begin to overflow and will not accept any new numbers. Ordinarily very few numbers remain in the stack for more than one gene or cycle, but sloppy or mutated DNA can cause this. It is easy to empty the stack by placing several add, sub, or mult commands in a row.