Go to the first, previous, next, last section, table of contents.


Fun With The Stack

Things you can do with the stack:

Pop things off it:

Stack: "This" "is" "a" "test"
pop
Stack: "This" "is" "a"
pop
Stack: "This" "is"
pop
Stack: "This"
pop
Stack: 
pop
Stack: 

**** Sorry: Stack underflow

Stack: 

Note that when I accidentally tried to pop an empty stack, MUF complained. (It didn't really sound very sorry. But then, it wasn't really very accidental either grin.)

You'll see that complaint a lot when you play with MUF, unless you are just inhumanly precise. It doesn't do any harm, other than stopping your command from getting any further. There's no secret log recording how often you get stack underflow that the system gurus read and snicker over. Honest! Mostly because the system gurus would probably lead the list...

Push things back on the stack, more than one at a time:

Stack:
"This" "is"
Stack: "This" "is"
"yet" "another" "test" "--" "really!"
Stack: "This" "is" "yet" "another" "test" "--" "really!"

Pop things back off the stack, more than one at a time:

Stack: "This" "is" "yet" "another" "test" "--" "really!"
pop pop
Stack: "This" "is" "yet" "another" "test"
pop pop pop pop
Stack: "This"
pop
Stack: 

Swap the top two things on the stack:

Stack: 
"1" "2" "3" "4"
Stack: "1" "2" "3" "4"
swap
Stack: "1" "2" "4" "3"
pop
Stack: "1" "2" "4"
swap
Stack: "1" "4" "2"

Circulate (rotate) the top three things on the stack:

Stack: "1" "4" "2"
rot
Stack: "4" "2" "1"
rot
Stack: "2" "1" "4"

(Forth code, and old-time MUF code, used to be full of swaps and rots because there weren't good variables, so the stack got over-used. Nowadays, you very seldom see them in good Muq MUF code. But they can still occasionally be handy when playing around interactively. We'll explain variables in a bit!)


Go to the first, previous, next, last section, table of contents.