Introduction to the SED (Stack Effect Diagram)
In order to know what a specific 8th word does with the stack, there is a special kind of documentation, called a Stack Effect Diagram for each 8th word.We always precede the SED with a \ (this is the 8th word to start a comment).
Then follow the relevant items on the stack before the word is invoked. Behind that is a double dash – which in turn is followed by the relevant items on the stack after executing the word.
The next paragraphs explain some 8th words together with their SED.
drop \ x –Remove the item at TOS. You can see that in the SED. Before executing the word drop the item x is at TOS and afterwards it is completely gone.
2drop \ x y –
Same as drop, but now 2 items are dropped.
dup \ x – x x
Duplicate the item on TOS.
2dup \ x y – x y x y
Same as dup, but now 2 items are duplicated.
nip \ x y – y
Remove the second item on the stack.
over \ x y – x y x
Copy the second item on the stack to TOS.
swap \ x y – y x
Exchange the two topmost items on the stack.
tuck \ x y – y x y
Copy the item at TOS and put it in third position.
More info about 8th
There is a central website for 8th here: http://8th-dev.com/Video
Watch the complementary video here
No comments:
Post a Comment