Typed evaln Parameter Checking
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.
| (1.1) |
| (1.2) |
Here, a evaluates to 3, which is not a name with an integer value.
| (1.3) |
The name b evaluates to 4.5, which is, again, not a name with an integer value.
| (1.4) |
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));
|
| (1.5) |
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));
|
| (1.6) |
A function that requires its argument to be an unevaluated name would have an integer value if evaluated.
>
|
f := proc(x::name(integer)) end;
|
| (1.7) |
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;
|
| (1.8) |
|
|
Useful Error Messages
|
|
The argument is evaluated to 3, which is not a name with an integer value.
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.
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.
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.
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.
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.
The argument is explicitly unevaluated, and is a name, but not with an integer value. Again note the meaningful error message.
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(...).
Error, illegal use of an object as a name
| |
Error, illegal use of an object as a name
| |
|
|
See Also
|
|
For more information, see the following help topics: type, evaln, name.
|
Return to Index for Example Worksheets
|