Define a Procedure - Maple Help

# Online Help

###### All Products    Maple    MapleSim

Define a Procedure

 Description Create a procedure by defining parameters, variables, and return values.

Define the procedure.

 > # Define the name and parameter(s) of the procedure. __f__ := proc(__l__::list(numeric)) # Define variables that are local to the procedure.         local __avg__, __i__; # Define the statements of the procedure.         __avg__ := add(__l__[__i__], __i__ = 1..nops(__l__))/nops(__l__); # Define the return value of the procedure.         return __avg__; end proc;
 ${f}{:=}{\mathbf{proc}}\left({l}{::}\left({\mathrm{list}}{}\left({\mathrm{numeric}}\right)\right)\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{local}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{avg}}{,}{i}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{avg}}{:=}{\mathrm{add}}{}\left({l}{[}{i}{]}{,}{i}{=}{1}{..}{\mathrm{nops}}{}\left({l}\right)\right){/}{\mathrm{nops}}{}\left({l}\right){;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{return}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{avg}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end proc}}$ (1)

Invoke the procedure.

 > __f__([1, 2, 4, 8, 16, 32, 64]);
 $\frac{{127}}{{7}}$ (2)
 Commands Used
 See Also