User Guide

8.4 Procedures
A Maple procedure is a program consisting of Maple statements. Using
procedures, you can quickly execute the contained sequence of statements.
Defining and Running Simple Procedures
To define a procedure, enclose a sequence of statements between proc(...)
and end proc statements. In general, you assign a procedure definition to a
name.
The following procedure returns the square root of 2.
p := proc() sqrt(2); end proc;>
Note: Maple returns the procedure definition.
To improve readability of procedures, it is recommended that you define a
procedure using multiple lines, and indent the lines using space characters.
To begin a new line (without evaluating the incomplete procedure definition),
press Shift+Enter. When you have finished entering the procedure, press
Enter to create the procedure.
For example:
p := proc()
sqrt(2);
end proc:
>
To run the procedure p, enter its name followed by parentheses (( )).
p();>
338 8 Basic Programming