Previous Next        Current Page: NeXtMidas User's Guide / Macros / Creating a New Macro / Macro Editing
back

Macro Editing

Even the best macro writers make mistakes. That's why the BACKSPACE key was invented. The two most common methods of locating a bug within a macro are printing debugging messages and making assertions.

Printing Debugging Messages

Debugging messages print out to the terminal while executing a macro with the /DEBUG switch turned on. Here is an example of a debugging message that you can add after Line 15 in the triangle macro (Macro Example: triangle.mm.) which allows you to see the type value while the macro is running:

if/debug then
   say"type = ^type"
endif

If debugging is turned off (/debug=OFF) this message is not printed.

With this debugging message, a macro writer sees whether a triangle is incorrectly identified as a 45 Deg. Right Triangle which might be the result of a typo in Line 13 (such as using the GT comparison when EQ is correct).

Using Assertions

The ASSERT command makes assertions about variables within the macro. It performs a test and prints out a message indicating whether the test passed or failed. If ASSERT is called with the /DEBUG switch, it only prints out messages if debugging is also turned on in the macro (i.e., the macro is called with the /DEBUG=ON switch).

To test whether lengthA and lengthB values are less than lengthH (as is appropriate for a triangle), try adding these lines after Line 9 in the triangle macro:

assert/debug/text="lengthA< lengthH" lengthA LT lengthH
assert/debug/text="lengthB< lengthH" lengthB LT lengthH

The results of these assertions show whether the computations in Lines 8 and 9 are correct. Anyone running the macro with debugging turned off (/DEBUG=OFF) is unaware this test exists within the macro file.


back