EasyManuals Logo

LEGO MINDSTORMS Robots User Manual

LEGO MINDSTORMS Robots
226 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #113 background image
77 12 55
ok
. .
55 12 ok
.
77 ok
If you understand the stack, you know almost everything there is to know about Forth.
Words and the Dictionary
The other important concept in Forth is the dictionary. This is simply a list of words and what they mean. A word is a simply a program with a name. To run it,
Page 122
you just type its name. Many programs expect to find input values on the stack and may place their results on the stack when they're done.
Built-in words
Forth has a number of simple words that are built in to the dictionary. DUP, for example, duplicates the top element of the stack. You can easily see how this works:
77
ok
DUP
ok
. .
77 77 ok
Table 6-2 lists some of the important built-in words in Forth. The table shows the stack before ("Initial Stack") and after ("Ending Stack") the word runs. By convention, the top is shown on the
right. For example, x1 x2 shows a stack with x2 at the top and x1 as the second item. This seems confusing at first, but it makes sense after a while (and it's the convention in Forth
documentation).
Table 6-2. Forth Built-in Words
Word Meaning Initial Stack Ending Stack
DUP
Duplicates the top item on the stack
x x x
OVER
Copies the second stack item
x1 x2 x1 x2 x1
PICK
Copies the nth stack item (n is zero-based)
… n … xn
SWAP
Switches the top two stack items
x1 x2 x2 x1
ROT
Moves the third stack item to the top
x1 x2 x3 x2 x3 x1
DROP
Discards the top item on the stack
x
Forth also supports mathematical operators, which operate on the top two items of the stack and leave their result at the top of the stack. For example, you can divide two numbers like this:
84 2 /
ok
.
42 ok

Table of Contents

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the LEGO MINDSTORMS Robots and is the answer not in the manual?

LEGO MINDSTORMS Robots Specifications

General IconGeneral
Product LineLEGO MINDSTORMS
CategoryToy
Age Range10+
Batteries RequiredYes
Memory64 MB RAM, 16 MB Flash
ConnectivityBluetooth, USB
SensorsTouch, Color, Gyro
Battery TypeAA
Interactive FeaturesProgrammable, Remote Control
App CompatibilityiOS, Android
ProcessorARM9
Pieces Count601
Battery Count6
App NameLEGO MINDSTORMS EV3 Programmer App

Related product manuals