A. Programming
:
**************************
Note: The syntax used in this part is quite general as it is
not exclusive to Logo. The examples in this section are of a general
nature, to show the inherent programming logic. The functions
described here are non-existent, and refer to every day life
examples. For actual functions, see the sections "Logo Syntax" and
"List of the Functions".
1.
Definitions:
Instruction : an instruction is an order
containing a certain number of parameters. An instruction is
identified by its name. For example, " eat " is an instruction with
no parameter while " eat (pear) " contains a parameter.
Variable : a variable is a reference to a
value; a value is identified by its name; for example, you can create
a variable named " Qwer " which has the value 12.
Parameter :: a parameter is a value or a
variable that modifies or defines the execution of a function. There
are many types of parameters : number, word, picture, sound, etc.
Procedure : a procedure is a limited group of
structured instructions. For example,
eat a pear
talk
look at the dog
is a procedure containing three instructions and is different from
the following procedure :
eat a pear
look at the dog
talk
because the order differs. You can give a name to a procedure and it
can be executed simply by naming it ( with the proper parameters ). A
procedure can also contain another procedure. For example, the
following procedure called " Blow ":
open your mouth
compress your lungs
can be executed within the following procedure called " Balloon
":
put the balloon in front of your mouth
Blow
So " Blow " is used as an instruction within a procedure. To achieve
the same, one could have written :
put the balloon in front of your mouth
open your mouth
compress your lungs
2. Procedure
language
Logo is a procedure language which implies that :
- we find in it sequence, iteration and
selection ( see below );
- the structure contains many procedures, nested ( one procedure
calls upon another ) and/or recurring ( one procedure calls itself ).
For example, the procedure " Around " could be :
go forward
turn left
Around
Such a procedure would cause problems, because it contains an
infinite loop. In practice, one would put in control
instructions ( see below ) to avoid this problem.
3. Sequence,
iteration, selection:
These three means determine the order in which the instructions are
carried out.
- The sequence is the simplest order
: one after the other. For example, the sequence:
eat a pear
look at the dog
talk
will be carried out in the written order.
-The iteration allows repeating an
instruction. For example the procedure :
eat a pear
look at the dog
repeat(5){talk}
is equivalent to
eat a pear
look at the dog
talk
talk
talk
talk
talk
-The selection allows an instruction
to be carried out if and only if a condition is met. For example, in
the following procedure,
eat a pear
look at the dog
if your mouth is empty then talk
the "if ... then" is a control instruction that puts a condition as
to whether that instruction will be carried out or not.