Next: Optional variables
Up: The workspace
Previous: The workspace
Contents
Index
Procedures are a kind of ``program''. When a procedure is called,
the instructions in the body of the procedure are executed. A procedure
is defined with the keyword to.
to name_of_procedure :v1 :v2 :v3 .... [:v4 ....] [:v5 ....]
Body of the procedure
end
- name_of_procedure is the name given to the procedure.
- :v1 :v2 :v3 stand for the variables used internally in this procedure. (local variables).
- [:v4 ... ], [:v5 ...] are optional variables that we could add into the procedure (go below for more explanations).
- Body of the procedure represents the commands to be executed when this procedure is called.
Eg:
to square :s
repeat 4[fd :s rt 90]
end
The procedure is called square and takes a parameter
called s. square 100 will therefore produce a square, the
length of whose sides is 100. (See the examples of procedures at the
end of this manual.)
Since version 0.7c, it is possible to insert comments in the code
preceded by #.
to square :s
#this procedure allows a square to be drawn whose side equals
:s.
repeat 4[fd :s rt 90] # handy, isn't it?
end
Subsections
Next: Optional variables
Up: The workspace
Previous: The workspace
Contents
Index
Loïc
2008-06-08