procedure - Maple Help

type/procedure

check for a procedure

 Calling Sequence type(expr, 'procedure') type(expr, 'procedure[rtype](type1, type2, ...)')

Parameters

 expr - any expression rtype, type1, type2, ... - any Maple types

Description

 • The first form of this command performs a surface type test for expressions of type procedure. This includes both builtin and library- or user-defined procedures. See procedure for more information about the definition and use of procedures.
 • Note the distinction between an expression of type procedure and one of type function, which might be better called a function call. In Maple it is the procedure type, rather than function that corresponds to what one thinks of as a mathematical function.
 • The second form of test is a structured type test for procedures whose arguments and (optionally) return types are declared to have a given type. (The term declared is a misnomer, since one of Maple's strengths is its complete lack of type declarations. However, for the purpose of dynamic type checking, it is useful to think of argument type specifier and return type assertion annotations in this way.)
 • A declared return type may be tested for by enclosing the type specifier rtype (which may be an arbitrary Maple type) for the return type in brackets immediately after the symbol procedure. Procedures that do not have a return type assertion are considered to have a declared return type of anything.
 • Explicitly declared parameter types may be tested for by enclosing the types in parentheses. The names of parameters are not considered, only their declared types. A procedure p has type procedure(T1, T2, ..., Tn), where T1, T2, ..., Tn are types, if it has exactly n declared parameters and the i-th parameter is declared to have type Ti, for each i. In other words, p must have been defined by a procedure definition of the form p := proc(t1::T1, t2::T2, ..., tn::Tn). A parameter whose type is not specified is considered to have been declared to have type anything.
 • Note that argument types and return types are both optional and may be tested independently of one another.
 • Currently, argument and return types must match exactly the types found in the procedure data structure. Subtype relationships are not computed.
 • Note that no builtin procedure has either return type assertions or declared parameter types.

Subtypes

 •
 Supertypes

Examples

The first few examples try to illustrate the sometimes confusing relationship between procedures and functions.

 > $\mathrm{type}\left(\mathrm{sin},'\mathrm{procedure}'\right)$
 ${\mathrm{true}}$ (1)
 > $\mathrm{type}\left(\mathrm{sin},'\mathrm{function}'\right)$
 ${\mathrm{false}}$ (2)
 > $\mathrm{type}\left(\mathrm{sin}\left(x\right),'\mathrm{procedure}'\right)$
 ${\mathrm{false}}$ (3)
 > $\mathrm{type}\left(\mathrm{sin}\left(x\right),'\mathrm{function}'\right)$
 ${\mathrm{true}}$ (4)
 > $\mathrm{type}\left(F,'\mathrm{procedure}'\right)$
 ${\mathrm{false}}$ (5)
 > $\mathrm{type}\left(F\left(x\right),'\mathrm{procedure}'\right)$
 ${\mathrm{false}}$ (6)
 > $\mathrm{type}\left(F\left(x\right),'\mathrm{function}'\right)$
 ${\mathrm{true}}$ (7)

Here are some examples of various kinds of procedures, and some non-examples.

 > f := proc(x) x^2 end proc;
 ${f}{≔}{\mathbf{proc}}\left({x}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{x}{^}{2}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end proc}}$ (8)
 > $\mathrm{type}\left(f,'\mathrm{procedure}'\right)$
 ${\mathrm{true}}$ (9)
 > $g≔t↦\frac{\mathrm{sin}\left(t\right)}{\mathrm{cos}\left(t\right)}:$
 > $\mathrm{type}\left(g,'\mathrm{procedure}'\right)$
 ${\mathrm{true}}$ (10)
 > $\mathrm{type}\left(\mathrm{nops},'\mathrm{procedure}'\right)$
 ${\mathrm{true}}$ (11)
 > $\mathrm{type}\left({x}^{2},'\mathrm{procedure}'\right)$
 ${\mathrm{false}}$ (12)
 > $\mathrm{type}\left(\mathbf{module}\left(\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{end module},'\mathrm{procedure}'\right)$
 ${\mathrm{false}}$ (13)

These examples illustrate the use of the structured procedure type.

 > $\mathrm{type}\left(\mathrm{sin},'\mathrm{procedure}\left(\mathrm{algebraic}\right)'\right)$
 ${\mathrm{true}}$ (14)
 > $\mathrm{type}\left(\mathrm{fopen},'\mathrm{procedure}\left(\left\{\mathrm{string},\mathrm{symbol}\right\},\mathrm{symbol}\right)'\right)$
 ${\mathrm{true}}$ (15)
 > $\mathrm{type}\left(\mathrm{fopen},'\mathrm{procedure}\left(\mathrm{string},\mathrm{symbol}\right)'\right)$
 ${\mathrm{false}}$ (16)
 > $\mathrm{type}\left(\mathrm{fopen},'\mathrm{procedure}\left(\left\{\mathrm{string},\mathrm{symbol}\right\}\right)'\right)$
 ${\mathrm{false}}$ (17)
 > p := proc( a::algebraic, n::integer)::algebraic; a^n end proc:
 > $\mathrm{type}\left(p,'\mathrm{procedure}\left[\mathrm{algebraic}\right]'\right)$
 ${\mathrm{true}}$ (18)
 > $\mathrm{type}\left(p,'\mathrm{procedure}\left[\mathrm{algebraic}\right]\left(\mathrm{algebraic},\mathrm{integer}\right)'\right)$
 ${\mathrm{true}}$ (19)
 > p := proc( a::algebraic, n::integer) a^n end proc: # no return type assertion
 > $\mathrm{type}\left(p,'\mathrm{procedure}\left(\mathrm{algebraic},\mathrm{integer}\right)'\right)$
 ${\mathrm{true}}$ (20)
 > $\mathrm{type}\left(p,'\mathrm{procedure}\left[\mathrm{anything}\right]\left(\mathrm{algebraic},\mathrm{integer}\right)'\right)$
 ${\mathrm{true}}$ (21)
 > $\mathrm{type}\left(p,'\mathrm{procedure}\left[\mathrm{algebraic}\right]\left(\mathrm{algebraic},\mathrm{integer}\right)'\right)$
 ${\mathrm{false}}$ (22)