|
|
|
to procname :input1 :input2 ... (special form)
command. Prepares Logo to accept a procedure definition. The
procedure will be named "procname" and there must not already be a procedure by that name. The inputs will be called "input1" etc. Any number of inputs are allowed, including none. Names of procedures and inputs are case-insensitive.
Unlike every other Logo procedure, TO takes as its inputs the actual words typed in the instruction line, as if they were all quoted, rather than the results of evaluating expressions to provide the inputs. (That's what "special form" means.)
This version of Logo allows variable numbers of inputs to a procedure. Every procedure has a MINIMUM, DEFAULT, and MAXIMUM number of inputs. (The latter can be infinite.)
The MINIMUM number of inputs is the number of required inputs, which must come first. A required input is indicated by the
:inputnamenotation.
to go fd 100 end to printabc :a :b :c (pr :a :b :c) end |
[:inputname default_value_expression]When the procedure is invoked, if actual inputs are not supplied for these optional inputs, the default value expressions are evaluated to set values for the corresponding input names. The inputs are processed from left to right, so a default value expression can be based on earlier inputs.
to proc :inlist [:startvalue first :inlist] ;...some code here end |
proc [a b c]then the variable INLIST will have the value [A B C] and the variable STARTVALUE will have the value A. If the procedure is invoked by saying
(proc [a b c] "x)then INLIST will have the value [A B C] and STARTVALUE will have the value X.
to go [:steps 100] fd :steps end |
[:inputname]This is a rest input rather than an optional input because there is no default value expression. There can be at most one rest input. When the procedure is invoked, the value of this input will be a list containing all of the actual inputs provided that were not used for required or optional inputs.
to proc :in1 [:in2 "foo] [:in3] ;...some code here end |
proc "xthen IN1 has the value X, IN2 has the value FOO, and IN3 has the value [] (the empty list). If it's invoked by saying
(proc "a "b "c "d)then IN1 has the value A, IN2 has the value B, and IN3 has the value [C D].
to proc :in1 [:in2 "foo] [:in3] 3 ;...some code here end |
|
|
|