3 lines
24 KiB
HTML
3 lines
24 KiB
HTML
<!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>07-EDITING-AND-SAVING</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="part9.htm">< Previous</a><span> | </span><a href="../Medley-Primer.html">Contents</a><span> | </span><a href="part11.htm">Next ></a></p><h1 style="padding-top: 3pt;padding-left: 35pt;text-indent: 0pt;text-align: left;"><a name="bookmark9">7. EDITING AND SAVING</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_056.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: left;">This chapter explains how to define functions, how to edit them, and how to save your work.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><h2 style="padding-left: 35pt;text-indent: 0pt;text-align: left;">Defining Functions </h2><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s3" style="padding-top: 4pt;padding-left: 107pt;text-indent: 0pt;text-align: justify;">DEFUN <span class="p">can be used to define new functions. The syntax for it is:</span></p><p class="s3" style="padding-top: 7pt;padding-left: 143pt;text-indent: 0pt;text-align: left;">(DEFUN (<functionname> (<parameter-list><body-of-function>))</p><p style="padding-top: 7pt;padding-left: 107pt;text-indent: 0pt;line-height: 106%;text-align: justify;">New functions can be created with <span class="s3">DEFUN </span>by typing directly into the Executive Window. Once defined, a function is a part of the Medley environment. For example, the function <span class="s3">EXAMPLE-ADDER </span>is defined in Figure 7-1.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 160pt;text-indent: 0pt;text-align: left;"><span><img width="397" height="126" alt="image" src="Image_057.gif"/></span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-top: 4pt;padding-left: 193pt;text-indent: 0pt;text-align: left;">Figure 7-1. Defining the Function <span class="s3">EXAMPLE-ADDER</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 107pt;text-indent: 0pt;text-align: left;">Now that the function is defined, it can be called from the Executive Window:</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 162pt;text-indent: 0pt;text-align: left;"><span><img width="397" height="126" alt="image" src="Image_058.gif"/></span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-top: 4pt;padding-left: 107pt;text-indent: 55pt;line-height: 164%;text-align: left;">Figure 7-2.. After <span class="s3">EXAMPLE-ADDER </span>is defined, it can he executed The function returns 6, after printing out the message.</p><p style="padding-left: 107pt;text-indent: 0pt;text-align: left;">Functions can also be defined using the editor DEdit described above. To do this, simply type</p><p class="s3" style="padding-top: 7pt;padding-left: 142pt;text-indent: 0pt;text-align: left;"><span class="p">(</span>ED <span class="s4">function-name ’</span>FUNCTIONS<span class="p">)</span></p><p style="padding-top: 7pt;padding-left: 107pt;text-indent: 0pt;text-align: left;">You will be told that no definition exists for the function, and a menu will pop up asking you what type of function you would like to create:</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 163pt;text-indent: 0pt;text-align: left;"><span><img width="394" height="164" alt="image" src="Image_059.gif"/></span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-top: 4pt;padding-left: 215pt;text-indent: 0pt;text-align: left;">Figure 7-3 Selecting a Function Template</p><p style="padding-top: 7pt;padding-left: 107pt;text-indent: 0pt;text-align: left;">Selecting the appropriate type will pop up an editor window with a function template. The use of the editor is explained in the Using the List Structure Editor section below.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><h2 style="padding-left: 35pt;text-indent: 0pt;text-align: left;">Simple Editing in the Executive Window </h2><p style="padding-top: 9pt;padding-left: 107pt;text-indent: 0pt;text-align: left;">First, type in an example function to edit:</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s3" style="padding-left: 197pt;text-indent: -54pt;line-height: 88%;text-align: left;">3/41> (defun your-first-function (a b) (if (> a b)</p><p class="s3" style="padding-left: 227pt;text-indent: 0pt;line-height: 88%;text-align: left;">’(the first is greater) ’(the second is greater)))</p><p style="padding-top: 6pt;padding-left: 107pt;text-indent: 0pt;text-align: left;">To run the function, type:</p><p class="s3" style="padding-top: 8pt;padding-left: 143pt;text-indent: 0pt;line-height: 88%;text-align: left;">3/42> (YOUR-FIRST-FUNCTION 3 5) (THE SECOND IS GREATER)</p><p style="padding-top: 6pt;padding-left: 107pt;text-indent: 0pt;text-align: left;">Now, let’s alter this. Type:</p><p class="s3" style="padding-top: 7pt;padding-left: 143pt;text-indent: 0pt;text-align: left;">3/43> FIX 41</p><p style="padding-top: 5pt;padding-left: 107pt;text-indent: 0pt;text-align: left;">Note that your original function is redisplayed, and ready to edit. (See Figure 7-4.)</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 166pt;text-indent: 0pt;text-align: left;"><span><img width="386" height="93" alt="image" src="Image_060.gif"/></span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-top: 4pt;padding-left: 215pt;text-indent: 0pt;text-align: left;">Figure 7-4. Using FIX to Edit a Fundion</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s10" style="padding-left: 107pt;text-indent: 0pt;text-align: left;">Move <span class="p">the text cursor to the appropriate place in the function by positioning the mouse cursor and pressing the left mouse button.</span></p><p class="s10" style="padding-top: 7pt;padding-left: 107pt;text-indent: 0pt;text-align: left;">Delete <span class="p">text by moving the caret to the beginning of the section to be deleted. Hold the right mouse button down and move the mouse cursor over the text. All of the</span></p><p style="padding-left: 107pt;text-indent: 0pt;text-align: left;">highlighted text between the caret and mouse cursor is deleted when you release the right mouse button.</p><p class="s10" style="padding-top: 7pt;padding-left: 107pt;text-indent: 0pt;text-align: left;">If you make a mistake, <span class="p">deletions can be undone. Press the UNDO key on the keypad to the left of the keyboard.</span></p><p style="padding-top: 7pt;padding-left: 107pt;text-indent: 0pt;text-align: left;">Now change <span class="s3">GREATER </span>to <span class="s3">BIGGER</span>:</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-top: 4pt;padding-left: 125pt;text-indent: -18pt;line-height: 107%;text-align: left;">1. Position the mouse cursor on the <span class="s3">G </span>of <span class="s3">GREATER </span>, and click the left mouse button. The text cursor is now where the mouse cursor is.</p><p style="padding-top: 6pt;padding-left: 125pt;text-indent: -18pt;text-align: left;">2. Next, press the right mouse button and hold it down. Notice that if you move the mouse cursor around, it will blacken the characters from the text cursor to the mouse cursor. Move the mouse so that the word "<span class="s3">GREATER </span>" is highlighted.</p><p style="padding-top: 7pt;padding-left: 107pt;text-indent: 0pt;text-align: left;">3. Release the right mouse button and <span class="s3">GREATER </span>is deleted.</p><p style="padding-top: 7pt;padding-left: 107pt;text-indent: 0pt;text-align: left;">4. Without moving the cursor, type in <span class="s3">BIGGER </span>.</p><p style="padding-top: 7pt;padding-left: 125pt;text-indent: -18pt;text-align: left;">5. There are two ways to end the editing session and run the function. One is to type Control-<span class="s9">X</span>. (Hold the Control key down, and type <span class="s9">X</span>.) Another is to move the text</p><p style="padding-left: 124pt;text-indent: 0pt;text-align: left;">cursor to the end of the line and crø In both cases, the function has been edited!</p><p style="padding-top: 7pt;padding-left: 107pt;text-indent: 0pt;text-align: left;">Try the new version of the function by typing:</p><p class="s3" style="padding-top: 8pt;padding-left: 142pt;text-indent: 0pt;line-height: 88%;text-align: left;">3/48> (YOUR-FIRST-FUNCTION 8 9) (THE SECOND IS BIGGER)</p><p style="padding-top: 6pt;padding-left: 107pt;text-indent: 0pt;text-align: left;">and get the new result, or you can type:</p><p class="s3" style="padding-top: 7pt;padding-left: 142pt;text-indent: 0pt;line-height: 11pt;text-align: left;">3/49> REDO 42</p><p class="s3" style="padding-left: 142pt;text-indent: 0pt;line-height: 11pt;text-align: left;">(THE SECOND IS BIGGER)</p><p style="text-indent: 0pt;text-align: left;"><br/></p><h2 style="padding-left: 35pt;text-indent: 0pt;text-align: left;">Using the List Structure Editor </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;">If the function you want to edit is not readily available (i.e. the function is not in the</p><p style="padding-left: 107pt;text-indent: 0pt;text-align: left;">Executive Window, and you can’t remember the history list number, or you simply have a lot of editing), use the List Structure Editor, often called SEdit. This editor is evoked with a call to <span class="s3">ED</span>:</p><p class="s3" style="padding-top: 6pt;padding-left: 17pt;text-indent: 0pt;text-align: center;">81<span class="s2"></span><span class="p">(</span>ED ’YOUR-FIRST-FUNCTION ’FUNCTIONS)</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 107pt;text-indent: 0pt;text-align: left;">Your function will be displayed in an edit window, as in Figure 7-5.</p><p style="padding-top: 7pt;padding-left: 107pt;text-indent: 0pt;text-align: left;">If there is no edit window on the screen, you will be prompted to create a window. As</p><p style="padding-left: 107pt;text-indent: 0pt;text-align: left;">before, hold the leff mouse button down, move the mouse until it form s a rectangle of an acceptable size and shape, then release the button. Your function definition will</p><p style="padding-left: 107pt;text-indent: 0pt;text-align: left;">automatically appear in this edit window.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 184pt;text-indent: 0pt;text-align: left;"><span><img width="336" height="131" alt="image" src="Image_061.gif"/></span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-top: 4pt;padding-left: 246pt;text-indent: 0pt;text-align: left;">Figure 7-5. An Edit Window</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 107pt;text-indent: 0pt;text-align: left;">Many changes are easily done with the structure editor. Notice that by pressing the left mouse button you can place the caret in position, and by pressing the middle mouse</p><p style="padding-left: 107pt;text-indent: 0pt;text-align: left;">button you can select atoms or s-expressions. Repeated pressing of the middle button selects bigger pieces of text.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-top: 4pt;padding-left: 107pt;text-indent: 0pt;text-align: left;">To add an expression that does not appear in the edit window (i.e., it cannot simply be underlined), place the caret at the insertion point and type it in.. For example, to</p><p style="padding-left: 107pt;text-indent: 0pt;line-height: 107%;text-align: left;">replace the first <span class="s3">GREATER </span>with <span class="s3">LARGER</span>, place the caret to the left of <span class="s3">GREATER </span>, as shown in Figure 7-6.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 184pt;text-indent: 0pt;text-align: left;"><span><img width="336" height="131" alt="image" src="Image_062.gif"/></span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 111pt;text-indent: 0pt;text-align: center;">Figure 7-6. Caret Placement Prior to Changing <span class="s3">GREATER </span>with <span class="s3">LARGER</span></p><p style="padding-top: 7pt;padding-left: 107pt;text-indent: 0pt;line-height: 107%;text-align: left;">Now press the DELETE key seven times, and type in <span class="s3">LARGER </span>. The window now looks like this:</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 184pt;text-indent: 0pt;text-align: left;"><span><img width="336" height="131" alt="image" src="Image_063.gif"/></span></p><p style="padding-top: 9pt;padding-left: 111pt;text-indent: 0pt;text-align: center;">Figure 7-7. <span class="s3">GREATER </span>Changed to <span class="s3">LARGER</span></p><p style="padding-top: 7pt;padding-left: 107pt;text-indent: 0pt;text-align: left;">Notice the asterisk in the left edge of the title bar of the window. This designates that the function has be changed. Now exit the edit session by typing Control-X, and the function will be redifined.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><h2 style="padding-left: 35pt;text-indent: 0pt;text-align: left;">Commenting Functions </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;">Text can be marked as a comment by typing a semi-colon before the text of the comment.</p><p class="s3" style="padding-top: 6pt;padding-left: 143pt;text-indent: 0pt;text-align: left;">; This is the form of a comment</p><p style="padding-top: 7pt;padding-left: 107pt;text-indent: 0pt;text-align: left;">Inside an editor window, the comment will be printed in a different font and may be moved to the far right of the code. SEdit is familiar with the Common Lisp convention of single comments being on the far right, double comments being justified with the</p><p style="padding-left: 107pt;text-indent: 0pt;text-align: left;">function level, and triple comments being on the far left, as is shown in Figure 7-8.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 192pt;text-indent: 0pt;text-align: left;"><span><img width="317" height="146" alt="image" src="Image_064.gif"/></span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-top: 4pt;padding-left: 228pt;text-indent: 0pt;text-align: left;">Figure 7-8. Placement of Comments</p><p style="padding-top: 7pt;padding-left: 107pt;text-indent: 0pt;text-align: justify;">There are other editor commands which can be very useful. To learn about them, read Appendix B of the <i>Release Notes</i>.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><h2 style="padding-left: 35pt;text-indent: 0pt;text-align: left;">File Functions and Variables: How to See and Save Them </h2><p style="padding-top: 9pt;padding-left: 107pt;text-indent: 0pt;text-align: justify;">With Medley, all work is done inside the Lisp environment. There is no operating system or command level other than the Executive Window. All functions and data</p><p style="padding-left: 107pt;text-indent: 0pt;text-align: justify;">structures are defined and edited using normal Lisp commands. This sertion describes tools in the Medley environment that will keep track of any changes that you make in the environment that you have not yet saved on files, such as defining new functions,</p><p style="padding-left: 107pt;text-indent: 0pt;text-align: justify;">changing the values of variables, or adding new variables. And it then has you save the changes in a file you specify. All of these functions are in the <span class="s3">INTERLISP </span>(<span class="s3">IL:</span>) package.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><h2 style="padding-left: 35pt;text-indent: 0pt;text-align: left;">File Variables </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;">Certain system-defined global variables are used by the file package to keep track of the environment as it stands. You can get system information by checking the values of</p><p style="padding-left: 107pt;text-indent: 0pt;text-align: left;">these variables. Two important variables follow.</p><p style="padding-top: 7pt;padding-left: 119pt;text-indent: -11pt;line-height: 107%;text-align: left;">• <span class="s3">FILELST </span>evaluates to a list, all files that yoU have loaded into the Medley environment.</p><p style="padding-top: 6pt;padding-left: 119pt;text-indent: -10pt;line-height: 106%;text-align: left;">• <i>filename</i><span class="s3">COMS </span>(Each file loaded into the Lisp environment has associated with it a global variable, whose name is formed by appending <span class="s3">COMS </span>to the end of the filename.) This variable evaluates to a list of all the functions, variables, bitmaps, windows, and soon, that are stored on that particular file.</p><p style="padding-top: 7pt;padding-left: 119pt;text-indent: 0pt;text-align: left;">For example, if you type:</p><p class="s3" style="padding-top: 7pt;padding-left: 143pt;text-indent: 0pt;text-align: left;">MYFILECOMS</p><p style="padding-top: 7pt;padding-left: 119pt;text-indent: 0pt;text-align: left;">the system will respond with something like:</p><p class="s3" style="padding-top: 7pt;padding-left: 149pt;text-indent: -6pt;line-height: 106%;text-align: left;">((FNS YOUR-FIRST-FUNCTION ) VARS))</p><p style="text-indent: 0pt;text-align: left;"><br/></p><h2 style="padding-left: 35pt;text-indent: 0pt;text-align: left;">Saving Interlisp-D on Files </h2><p style="padding-top: 9pt;padding-left: 107pt;text-indent: 0pt;line-height: 107%;text-align: left;">The functions <span class="s3">(FILES?) </span>and <span class="s3">(MAKEFILE </span>’<i>filename</i><span class="s3">) </span>are useful when it is time to save function, variables, windows, bitmaps, records and whatever else to files.</p><p class="s3" style="padding-top: 6pt;padding-left: 179pt;text-indent: -69pt;line-height: 107%;text-align: left;">(FILES?) <span class="p">displays a list of variables that have values and are not already a part of any file, and then the functions that are not already part of any file.</span></p><p style="padding-top: 6pt;padding-left: 179pt;text-indent: 0pt;text-align: left;">Type:</p><p class="s9" style="padding-top: 7pt;padding-left: 203pt;text-indent: 0pt;text-align: left;">(FILES?)</p><p style="padding-top: 7pt;padding-left: 179pt;text-indent: 0pt;text-align: left;">the system will respond with something like:</p><p class="s3" style="padding-top: 7pt;padding-left: 203pt;text-indent: 0pt;line-height: 106%;text-align: left;">the variables: MY.VARIABLE CURRENT.TURTLE...to be dumped</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s3" style="padding-top: 5pt;padding-left: 203pt;text-indent: 0pt;line-height: 106%;text-align: left;">the functions: RIGHT LEFT FORWARD BACKWARD CLEAR-SCREEN...to be dumped</p><p class="s3" style="padding-top: 7pt;padding-left: 203pt;text-indent: 0pt;text-align: left;">want to say where the above go?</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 179pt;text-indent: 0pt;text-align: left;">If you type Y, the system will prompt with each item. There are three options:</p><p style="padding-top: 7pt;padding-left: 197pt;text-indent: -17pt;text-align: left;">1. To save the item, type the filename (unquoted) of the file where the item should be placed. (This can be a brand new file or an existing file.)</p><p style="padding-top: 7pt;padding-left: 179pt;text-indent: 0pt;text-align: left;">2. To skip the item, without removing it from consideration the next</p><p style="padding-left: 197pt;text-indent: 0pt;line-height: 107%;text-align: left;">time <span class="s3">(FILES?) </span>is called, type crø This will allow you to postpone the decision about where to save the item.</p><p style="padding-top: 6pt;padding-left: 197pt;text-indent: -18pt;text-align: left;">3. If the item should not be saved at all, type ]. Nowhere will appear after the item.</p><p style="padding-top: 7pt;padding-left: 179pt;text-indent: 0pt;text-align: left;">Part of an example interaction is shown in the following figure:</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 128pt;text-indent: 0pt;text-align: left;"><span><img width="487" height="274" alt="image" src="Image_065.gif"/></span></p><p style="padding-top: 6pt;padding-left: 172pt;text-indent: 0pt;text-align: left;">Figure 7-9. Part of an interaction using the function <span class="s3">FILES?</span></p><p class="s3" style="padding-top: 7pt;padding-left: 179pt;text-indent: 0pt;text-align: left;">(FILES?) <span class="p">assembles the items by adding them to the appropriate file’s</span></p><p class="s3" style="padding-left: 179pt;text-indent: 0pt;line-height: 107%;text-align: left;">COMS <span class="p">variable (see the File Variables section above). </span>(FILES?) <span class="p">does NOT write the file to secondary storage (disks or floppies). It only</span></p><p style="padding-left: 179pt;text-indent: 0pt;text-align: left;">upclates the global variables discussed in the File Variables section above.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s3" style="padding-left: 107pt;text-indent: 0pt;text-align: left;">(MAKEFILE ’filename)</p><p style="padding-top: 7pt;padding-left: 179pt;text-indent: 0pt;line-height: 165%;text-align: left;">actually writes the file to secondary storage. Type:</p><p class="s9" style="padding-left: 34pt;text-indent: 0pt;line-height: 11pt;text-align: center;">(MAKEFILE ’MY.FILE.NAME)</p><p style="padding-top: 7pt;padding-left: 179pt;text-indent: 0pt;text-align: left;">and the system will create the file. The function returns the full name of the file created. (i.e. <span class="s3">{DSK}MY.FlLE.NAME.; 1 </span>).</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-top: 4pt;padding-left: 179pt;text-indent: 0pt;line-height: 107%;text-align: left;">Files written to <span class="s3">(DSK) </span>are permanent files. They can be removed only by the user deleting them or by reformatting the disk.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 107pt;text-indent: 0pt;text-align: left;">Other file manipulation functions can be foun d in Chapter 4.</p><p class="nav"> </p><p class="nav"> </p><p class="nav"><a href="part9.htm">< Previous</a><span> | </span><a href="../Medley-Primer.html">Contents</a><span> | </span><a href="part11.htm">Next ></a></p><p class="nav"> </p></body></html>
|