1
0
mirror of synced 2026-01-24 19:51:16 +00:00
2021-01-22 15:26:25 -08:00

3 lines
14 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><title>10-BREAK-MENU</title><link href="navigation.css" rel="stylesheet" type="text/css"/><link href="document.css" rel="stylesheet" type="text/css"/></head><body><p class="top_nav"><a href="part12.htm">&lt; Previous</a><span> | </span><a href="../Medley-Primer.html">Contents</a><span> | </span><a href="part14.htm">Next &gt;</a></p><h1 style="padding-top: 3pt;padding-left: 35pt;text-indent: 0pt;text-align: left;"><a name="bookmark12">10. BREAKPACKAGE</a></h1><p style="padding-left: 35pt;text-indent: 0pt;line-height: 6pt;text-align: left;"><span><img width="640" height="8" alt="image" src="Image_071.png"/></span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-top: 15pt;padding-left: 107pt;text-indent: 0pt;text-align: justify;">The Break Package is a part of Interlisp that makes debugging your programs much easier.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><h2 style="padding-left: 35pt;text-indent: 0pt;text-align: left;">Break Windows </h2><p style="padding-top: 9pt;padding-left: 107pt;text-indent: 0pt;text-align: justify;">A break is a function either called by the programmer or by the system when an error has occurred. A separate window opens for each break. This window works much like the Executive Window, except for extra menus unique to a break window. Inside a</p><p style="padding-left: 107pt;text-indent: 0pt;text-align: justify;">break window, you can examine variables, look at the call stack at the time of the</p><p style="padding-left: 107pt;text-indent: 0pt;text-align: justify;">break, or call the editor. Each successive break opens a new window, where you can execute functions without disturbing the original system stack. These windows</p><p style="padding-left: 107pt;text-indent: 0pt;text-align: justify;">disappear when you resolve the break and return to a higher level.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><h2 style="padding-left: 35pt;text-indent: 0pt;text-align: left;">Break Package Example </h2><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-top: 4pt;padding-left: 107pt;text-indent: 0pt;text-align: left;">This example illustrates the basic break package functions. A more complete explanation of the breaking functions, and the break package will follow.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 107pt;text-indent: 0pt;text-align: left;">The correct definition of <span class="s3">FACTORIAL </span>is:</p><p class="s3" style="padding-top: 10pt;padding-left: 173pt;text-indent: -30pt;line-height: 106%;text-align: left;">(defun factorial (x) (if (zerop x)</p><p class="s3" style="padding-left: 203pt;text-indent: 0pt;line-height: 9pt;text-align: left;">1</p><p class="s3" style="padding-left: 197pt;text-indent: 0pt;line-height: 11pt;text-align: left;">(* x (factorial (1- x)))))</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 107pt;text-indent: 0pt;line-height: 107%;text-align: left;">To demonstrate the break package, we have edited in an error: <span class="s3">DUMMY </span>in the IF statement is an unbound atom, it lacks a value.</p><p class="s3" style="padding-top: 9pt;padding-left: 173pt;text-indent: -30pt;line-height: 106%;text-align: left;">((defun factorial (x) (if (zerop x)</p><p class="s3" style="padding-left: 203pt;text-indent: 0pt;line-height: 9pt;text-align: left;">dummy</p><p class="s3" style="padding-left: 197pt;text-indent: 0pt;line-height: 11pt;text-align: left;">(* x (factorial (1- x)))))</p><p style="padding-top: 5pt;padding-left: 107pt;text-indent: 0pt;text-align: left;">The evaluated function</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s3" style="padding-left: 143pt;text-indent: 0pt;text-align: left;">(FACTORIAL 4)</p><p style="padding-top: 7pt;padding-left: 107pt;text-indent: 0pt;line-height: 106%;text-align: left;">should return 24, but the above function has an error. <span class="s3">DUMMY </span>is an unbound atom, an atom without an assigned value, so Lisp will &quot;break&quot;. A break window appears (Figure 10-1), that has all the functionality of the typing lisp expressions into the Executive</p><p style="padding-left: 107pt;text-indent: 0pt;text-align: left;">Window (The top level), in addition to the break menu functions. Each consecutive break will move to another level &quot;down&quot;.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 158pt;text-indent: 0pt;text-align: left;"><span><img width="403" height="124" alt="image" src="Image_072.gif"/></span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-top: 4pt;padding-left: 247pt;text-indent: 0pt;text-align: left;">Figure 10-1. Break Window</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 107pt;text-indent: 0pt;text-align: left;">Move the mouse cursor into the break window and hold down the middle mouse button.</p><p style="padding-left: 107pt;text-indent: 0pt;text-align: left;">The Break Menu will appear. Choose BT. Another menu, called the stack menu, will appear beside the break window. Choosing stack items from this menu will display</p><p style="padding-left: 107pt;text-indent: 0pt;text-align: justify;">another window. This window displays the functions local variable bindings, or values (see Figure 10-2). This new window, titled FACTORlAL Frame, is an inspector window (see inspector Chapter 17).</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 140pt;text-indent: 0pt;text-align: left;"><span><img width="455" height="230" alt="image" src="Image_073.gif"/></span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-top: 4pt;padding-left: 208pt;text-indent: 0pt;text-align: left;">Figure 10-2. Back Trace of the System Stack</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 107pt;text-indent: 0pt;text-align: left;">From the break window, you can call the editor for the function <span class="s3">FACTORIAL </span>by <span class="s3">middle- buttoning on the word FACTORIAL and selecting DisplayEdit from the menu that pops up</span>.</p><p style="padding-top: 7pt;padding-left: 107pt;text-indent: 0pt;text-align: left;">Replace the unbound atom <span class="s3">DUMMY </span>with 1. Exit the editor .</p><p style="padding-top: 7pt;padding-left: 107pt;text-indent: 0pt;text-align: left;">The function is fixed, and you can restart it from the last call on the stack. (It does not have to be started again from the Top Level.) To begin again from the last call on the stack, choose the last (top) <span class="s3">FACTORIAL </span>call in the BT menu. Select R<span class="s3">EVERT </span>from the middle button break window, or type it into the window. The break window will close, and a new one will appear with the message: <span class="s9">Breakpoint at FACTORIAL</span></p><p style="padding-top: 7pt;padding-left: 107pt;text-indent: 0pt;line-height: 107%;text-align: left;">To start execution with this last call to <span class="s3">FACTORIAL </span>, choose OK from the middle button break menu. The break window will disappear, and the correct answer, 24, will be</p><p style="padding-left: 107pt;text-indent: 0pt;line-height: 11pt;text-align: left;">returned to the top level.</p><p class="s6" style="padding-top: 3pt;text-indent: 0pt;text-align: right;">10. BREAKPACKAGE</p><p style="padding-left: 35pt;text-indent: 0pt;line-height: 1pt;text-align: left;"><span><img width="665" height="1" alt="image" src="Image_074.png"/></span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><h2 style="padding-left: 35pt;text-indent: 0pt;text-align: left;">Ways to Stop Execution from the Keyboard (Breaking Lisp) </h2><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-top: 4pt;padding-left: 107pt;text-indent: 0pt;text-align: left;">There are ways you can stop execution from the keyboard. They differ in terms of how much of the current operating state is saved:</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-top: 7pt;padding-left: 107pt;text-indent: 0pt;text-align: left;">Control-G Provides you with a menu of processes to interrupt. Your process will</p><p style="padding-left: 179pt;text-indent: 0pt;line-height: 107%;text-align: left;">usually be &quot;<span class="s3">EXEC</span>&quot;. Choose it to break your process. A break window will then appear.</p><p style="padding-top: 9pt;padding-left: 179pt;text-indent: -71pt;text-align: left;">Control-B Causes your function to break, saves the stack, then displays a break window with all the usual break functions. For information on other interrupt characcers, see Chapter 30 in the <i>IRM</i>.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><h2 style="padding-left: 35pt;text-indent: 0pt;text-align: left;">Break Menu </h2><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-top: 4pt;padding-left: 107pt;text-indent: 0pt;text-align: left;">Move the mouse cursor into the break window. Hold the middle button down, and a new menu will pop up, like the one in Figure 10-3.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 286pt;text-indent: 0pt;text-align: left;"><span><img width="69" height="110" alt="image" src="Image_075.gif"/></span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-top: 4pt;padding-left: 191pt;text-indent: 0pt;text-align: left;">Figure 10-3. Middle Button Menu in Break window</p><p style="padding-top: 7pt;padding-left: 107pt;text-indent: 0pt;text-align: left;">Five of the selections are particularly important when just starting to use Medley:</p><p class="s3" style="padding-top: 7pt;padding-left: 107pt;text-indent: 0pt;text-align: left;">BT <span class="p">Back Trace displays the stack in a menu beside the break window. Back</span></p><p style="padding-left: 155pt;text-indent: 0pt;text-align: left;">Trace is a very powerful debugging tool. Each function call is placed on the</p><p style="padding-left: 155pt;text-indent: 0pt;text-align: left;">stack and removed when the execution of that function is complete. Choosing an item on the stack will open another window displaying that items local</p><p style="padding-left: 155pt;text-indent: 0pt;text-align: left;">variables and their bindings. This is an inspector window that offers all the power of the inspector. (For details, see the section on the Inspector, Chapter 17.)</p><p class="s3" style="padding-top: 7pt;padding-left: 155pt;text-indent: -48pt;line-height: 107%;text-align: left;">? = <span class="p">Before you use this menu option, display the stack by choosing BT from this menu, and choose a function from it. Now, choose ?=. It will display the</span></p><p style="padding-left: 155pt;text-indent: 0pt;text-align: left;">current values of the arguments to the function that has been chosen from the stack.</p><p class="s2" style="padding-top: 6pt;padding-left: 155pt;text-indent: -48pt;text-align: left;"><span class="p"> Move back to the previous break window, or if there is no other break window, back to the top level, the Executive Window.</span></p><p class="s3" style="padding-top: 7pt;padding-left: 155pt;text-indent: -48pt;text-align: justify;">REVERT <span class="p">Move the point of execution back to a specified function call before the error. The function to revert back to is, by default, the last function call before the break. If, however, a different function call is chosen on the BT menu, revert will go back to the start of this function and open a new break window. The</span></p><p style="padding-left: 155pt;text-indent: 0pt;text-align: justify;">items on the stack above the new starting place will no longer exist. This is used in the tutorial example (see the Break Package Example section above).</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s3" style="padding-top: 4pt;padding-left: 155pt;text-indent: -48pt;line-height: 107%;text-align: left;">OK <span class="p">Continue execution from the point of the break. This is useful if you have a simple error, i.e., an unbound variable or a nonnumeric argument to an</span></p><p style="padding-left: 155pt;text-indent: 0pt;text-align: left;">arithmetic function. Reset the variable in the break window, then select OK. (see the Break Package Example section above).</p><p style="padding-top: 9pt;padding-left: 107pt;text-indent: 0pt;text-align: left;">In addition to being available on the middle button menu of the break window, all of these functions can be typed directly into the window. Only BT behaves differently</p><p style="padding-left: 107pt;text-indent: 0pt;text-align: left;">when typed. It types the stack into the trace window instead of opening a new window.)</p><p style="text-indent: 0pt;text-align: left;"><br/></p><h2 style="padding-left: 35pt;text-indent: 0pt;text-align: left;">Returning to Top Level </h2><p style="padding-top: 9pt;padding-left: 107pt;text-indent: 0pt;text-align: left;">Typing Control-D will immediately take you to the top level from any break window.</p><p style="padding-left: 107pt;text-indent: 0pt;text-align: left;">The functions called before the break will stop, but any side effect s of the function that occurred before the break remain. For example, if a function set a global variable before it broke, the variable will still be set after typing Control-D.</p><p class="nav">&nbsp;&nbsp;</p><p class="nav">&nbsp;</p><p class="nav"><a href="part12.htm">&lt; Previous</a><span> | </span><a href="../Medley-Primer.html">Contents</a><span> | </span><a href="part14.htm">Next &gt;</a></p><p class="nav">&nbsp;&nbsp;</p></body></html>