The Warnings Package
Douglas Wilhelm Harder, July 29th, 2002
Students new to Maple often make mistakes such as:
1. Using equals instead of assignment, e.g., x = 3; instead of x := 3;. 2. Using pi and i instead of Pi and I, respectively. 3. Using remember table assignment instead of operator assignment, e.g., f(x) := x^2; instead of f := x -> x^2; 4. Forgetting multiplication signs which do not cause errors, e.g., x(x - 1)(x + 1) instead of x*(x - 1)*(x + 1). 5. Using short cuts in entering functions, e.g., sinx instead of sin(x). 6. Using matrix and vector instead of Matrix and Vector.
These mistakes can be difficult to find. The Warnings package gives feedback to the user immediately after the expression is evaluated. After saving this package to a library or executing this worksheet, the user can enter:
> Warnings:-StartWarnings();
Then, when something suspicious arises, a Maplet appears with the warning. The first text box on the Maplet gives what the expression evaluated to, and the second gives a possible correction. Each type of correction can be turned off by clicking the check box at the bottom of the Maplet or by using the Understood export of the Warnings package. StopWarnings turns the warnings off and ResetWarnings turns all warnings back on. For efficiency purposes, if the output is a 2D or 3D plot, the evaluated object is not inspected. When the user presses Enter, the evaluated result is inspected for problems like those listed above. While it is possible to make changes to the evaluation, it is probably better to alert the user to the problem and have them go back and manually check it. Otherwise, they will continue to use this feature instead of learning the correct syntax. The package is aware of all the errors listed above by using the AddWarning export of the package. The package can be extended using the same routine. AddWarning takes two arguments, the first is a symbol which must be unique, and the second is a procedure which takes as input one argument which is a list of the result of the user's evaluation. The output must be an expression sequence of two strings if a problem was found or false otherwise. For example, the following routine returns a warning if the user uses f instead of F:
Warnings[AddWarning]( useF, proc(input) if has( input, 'f' ) then "You used the varible f. You should use F:", sprintf( "%q;", op( subs( 'f' = 'F', [args] ) ) ); else 'false'; end if; end proc );
This routine also takes a few additional options: You may select a non-default title using the title = "...." option. A check is made to ensure you do not add a warning with the same unique identifier as one already in the database. You can turn this check off by explicitly giving the option check = false.
Note, since warnings are suppose to help the student, if the procedure included with AddWarning ever generates an error or invalid output, that problem is silently ignored. The student is having enough problems as it is without having to deal with problems caused by the author. In order to see these errors, you can use the option report_errors = true when you call StartWarnings.
The exports UserNames and UserFunctions return a set of all non-library names and function names which have been used up until that point.
Warnings Source Code
p = x^2 + 2*x + 3
f(x) = x^2 + 3;
x (x + 3)
sin^3(x + 1), sin^n(x + 1)
f(x) := x^2;
pi
i
sinx, cosx, etc.
matrix and vector
This cannot be caught:
But the aftershocks can: