COMP203: Lecture 21

See Moodle for Final Project Assignments

Procedures in Maple and Logo

Procedures in Maple are conceptually similar to procedures in Logo, but the two types of procedure differ in some details -- like punctuation. Shown below are two procedure definitions, one from each language:

Logo:

Maple:

In Logo we use the command to to indicate that what follows is a function. In Maple we use the function proc().

In Logo the variable names for the procedure's inputs are typed after the procedure name, separated by spaces. In Maple the variable names are inputs to proc().

In Logo, the procedure name is an input to the to command. In Maple the procedure name is the name of the variable that the procedure is stored in.

On the second line of the procedures we see that Logo requires an output command, while Maple procedures simply output the last value calculated.

Finally, Logo procedures end with the word "end" and Maple procedure end with "end proc". Typing a colon after "end proc" in place of a semicolon will prevent Maple from reprinting the function definition.

Local variables and semicolons

In Maple, it is a good idea to end every line in a procedure -- except the line containing proc() -- with a semicolon.

Like Logo, Maple procedures can create local or global variables. Logo procedures create global variables unless you use a local command to tell them not to. Maple procedures create local variables (and give you a warning) unless you use a global command to tell them not to.

If you don't use a semicolon at the end of a local or global command, Maple will probably give you an error message.

For loops in Maple and Logo

In Logo, the instruction:

for [i 0 10 2] [print :i]

displays the even integers from 0 to 10 on the computer screen.

In Maple, the instruction: for i from 0 to 10 by 2 do i; od;

has the same effect.

Instead of Logo's list of controls [i 0 10 2], Maple uses keywords that are much more descriptive of what the for loop will do.

Where Logo uses square brackets [] to indicate the start and end of the block of instructions to repeat, Maple uses do and od.

Logo only displays values if they're input to print, show or type, while Maple evaluates expressions and displays the results by default.

Still, there are more similiarities than differences in the function of for loops in the two programming languages.