Typed evaln Parameter Checking
restart:
This worksheet illustrates, by means of several examples, a feature in the Maple type system.
Specifying Parameters of Type name
The Maple parameter type checking allows you to specify that a parameter is to remain as a name (that is, x::evaln), while also specifying that this name must be assigned a particular sort of value.
The two types involved in doing this are:
name(<type-specification>)
and
evaln(<type-specification>)
These are semantically equivalent to name and evaln, with the additional restriction that the specified name must be assigned a value that matches the <type-specification>. Note that when making the test on the assigned value, the assigned value is not evaluated any further than it will have been already.
a := 3;
a:=3
b := 4.5;
b:=4.5
Here, a evaluates to 3, which is not a name with an integer value.
type(a,name(integer));
false
The name b evaluates to 4.5, which is, again, not a name with an integer value.
type(b,name(integer));
In the next example, the name a does evaluate to an integer value. The type function itself sees the name a, because it has been quoted.
type('a',name(integer));
true
Here, the quoted 'b' evaluates to a name, but it is not bound to an integer, so the result is false.
type('b',name(integer));
A function that requires its argument to be an unevaluated name would have an integer value if evaluated.
f := proc(x::name(integer)) end;
f:=procx::name⁡integerend proc
A function that requires its argument to be a name (implicitly unevaluated) would have an integer value if evaluated.
g := proc(x::evaln(integer)) end;
g:=procx::evaln⁡integerend proc
Useful Error Messages
The argument is evaluated to 3, which is not a name with an integer value.
f(a);
Error, invalid input: f expects its 1st argument, x, to be of type name(integer), but received 3
The argument is evaluated to 4.5, which is not a name with an integer value.
f(b);
Error, invalid input: f expects its 1st argument, x, to be of type name(integer), but received 4.5
The argument is evaluated to 'a', which is a name with an integer value.
g(a);
The argument is evaluated to 'b', which is a name, but not with an integer value. Note that the error message clearly indicates this. This cannot be confused with having received an actual assignment statement--that is not possible.
g(b);
Error, invalid input: g expects its 1st argument, x, to be of type evaln(integer), but received b := 4.5
If you pass an unassigned name, the error message indicates the problem.
g(c);
Error, invalid input: g expects its 1st argument, x, to be of type evaln(integer), but received c := c
The argument is explicitly unevaluated, and is a name with an integer value.
f('a');
The argument is explicitly unevaluated, and is a name, but not with an integer value. Again note the meaningful error message.
f('b');
Error, invalid input: f expects its 1st argument, x, to be of type name(integer), but received b := 4.5
An explicitly unevaluated name does not match a parameter of type evaln (it never did) or evaln(...).
g('a');
Error, illegal use of an object as a name
g('b');
See Also
For more information, see the following help topics: type, evaln, name.
Return to Index for Example Worksheets
Download Help Document