1
0
mirror of synced 2026-04-24 19:40:36 +00:00
Files
Interlisp.medley/docs/html-primer/Medley-Primer_files/part130.htm
2021-01-22 22:41:07 +00:00

3 lines
8.6 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>Naming Variables and Records </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="part129.htm">&lt; Previous</a><span> | </span><a href="../Medley-Primer.html">Contents</a><span> | </span><a href="part131.htm">Next &gt;</a></p><h2 style="padding-left: 35pt;text-indent: 0pt;text-align: left;">Naming Variables and Records </h2><p style="padding-top: 9pt;padding-left: 107pt;text-indent: 0pt;text-align: left;">You will find times when one environment simultaneously hosts a number of different programs. Running a demo of several programs, or reloading the entire Medley</p><p style="padding-left: 107pt;text-indent: 0pt;text-align: left;">environment from floppies when it contains several different programs, are two</p><p style="padding-left: 107pt;text-indent: 0pt;text-align: left;">examples that could, if you arent careful, provide a few problems. Here are a few tips on how to prevent problems:</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 119pt;text-indent: -10pt;line-height: 107%;text-align: justify;">• If you change the value of a system variable, <span class="s3">MENUHELDWAIT </span>for example, or connect to a directory other than <span class="s3">{DSK}&lt;LISPFILES&gt; </span>, write a function to reset the variable or directory to its original value. Run this function when you are finished working.</p><p style="padding-left: 119pt;text-indent: 0pt;line-height: 11pt;text-align: justify;">This is especially important if you change any of the system menus.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 119pt;text-indent: -10pt;text-align: left;">• Do not redefine Medley functions or CLISP words. Remember, if you reset an atoms value or function definition at the top level (in the Executive Window), the message (<i>Some.Crucial.Function.Or.Variable </i><span class="s3">redefined) </span>, appears. If this is not what you wanted, type <span class="s9">UNDO </span>immediately!</p><p style="padding-top: 10pt;padding-left: 119pt;text-indent: 0pt;text-align: left;">If, however, you reset the value or function definition of an atom inside your program, a warning message will not be printed.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 119pt;text-indent: -10pt;text-align: left;">• Make the atom names in your programs as unique as possible. To do this without filling your program with unreadable names that noone, including you, can</p><p style="padding-left: 119pt;text-indent: 0pt;text-align: left;">remember, prefix your variable names with the initials of your program. Even then, check to see that they are not already being used with the function <span class="s3">BOUNDP </span>. For</p><p style="padding-left: 119pt;text-indent: 0pt;text-align: left;">example, type:</p><p class="s3" style="padding-top: 7pt;padding-left: 179pt;text-indent: 0pt;text-align: left;">(BOUNDP BackgroundMenu)</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 119pt;text-indent: 0pt;text-align: left;">This atom is bound to the menu that appears when you press the leff mouse button</p><p style="padding-left: 119pt;text-indent: 0pt;text-align: left;">when the mouse cursor is not in any window. <span class="s3">BOUND</span>P returns <span class="s3">T</span>. <span class="s3">BOUNDP </span>returns <span class="s3">NIL</span></p><p style="padding-left: 119pt;text-indent: 0pt;text-align: left;">if its argument does not currently have a value.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 108pt;text-indent: 0pt;text-align: left;">• Make your function names as unique as possible. Once again, prefixing function</p><p style="padding-left: 119pt;text-indent: 0pt;text-align: left;">names with the initials of your program can be helpful in making them unique, but even so, check to see that they are not already being used. <span class="s3">GETD </span>is the Interlisp-D function that returns the function definition of an atom, if it has one. If an atom has no function definition, <span class="s3">GETD </span>returns <span class="s3">NIL</span>. For example, type:</p><p class="s3" style="padding-top: 7pt;padding-left: 143pt;text-indent: 0pt;text-align: left;">(GETD CAR)</p><p style="padding-top: 7pt;padding-left: 119pt;text-indent: 0pt;text-align: left;">A non-<span class="s3">NIL </span>value is returned. The atom <span class="s3">CAR </span>already has a function definition.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 119pt;text-indent: -11pt;line-height: 107%;text-align: left;">• Use complete record field names in record <span class="s3">FETCH</span>es and <span class="s3">REPLACE </span>s when your code is not compiled. A complete record field name is a list consisting of the record</p><p style="padding-left: 119pt;text-indent: 0pt;line-height: 11pt;text-align: justify;">declaration name and the field name. Consider the following example:</p><p class="s3" style="padding-top: 7pt;padding-left: 143pt;text-indent: 0pt;line-height: 10pt;text-align: left;">(REC0RD NAME (FIRST LAST))</p><p class="s3" style="padding-left: 143pt;text-indent: 0pt;line-height: 88%;text-align: left;">(SETQ MyName (create Name FIRST <span class="s2"></span>John LAST <span class="s2"></span>Smith)) (FETCH (NAME FIRST) OF MyName)</p><p style="padding-top: 9pt;padding-left: 119pt;text-indent: -11pt;text-align: left;">• Avoid reusing names that are field names of Lisp system records. A few examples of system records follow. Do not reuse these names.</p><p class="s3" style="padding-top: 7pt;padding-left: 143pt;text-indent: 0pt;line-height: 88%;text-align: left;">(RECORD REGION (LEFT BOTTOM WIDTH HEIGHT)) (RECORD POSITION (XCOORD YCOORD))</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s3" style="padding-top: 4pt;padding-left: 143pt;text-indent: 0pt;text-align: left;">(RECORD IMAGEOBJ (- BITMAP -<span class="p">)))</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 119pt;text-indent: -11pt;text-align: left;">• When you select a record name and field names for a new record, check to see whether those names have already been used.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 119pt;text-indent: 0pt;line-height: 107%;text-align: left;">Call the function <span class="s3">RECLOOK</span>, with your record name as an argument, in the Executive Window (see Figure 22-1). If your record name is already a record, the record</p><p style="padding-left: 119pt;text-indent: 0pt;line-height: 12pt;text-align: left;">definition will be returned; otherwise the function will return <span class="s3">NIL</span>.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 191pt;text-indent: 0pt;text-align: left;"><span><img width="329" height="142" alt="image" src="Image_154.gif"/></span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 230pt;text-indent: 0pt;text-align: left;">Figure 22-1. Response to <span class="s3">RECLOCK</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-top: 7pt;padding-left: 119pt;text-indent: 0pt;line-height: 106%;text-align: left;">Call the function <span class="s3">FIELDLOOK </span>with your new field name in the Executive Window (see Figure 22-2). If your field name is already a field name in another record, the record definition will be returned; otherwise the function will return <span class="s3">NIL</span>.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 188pt;text-indent: 0pt;text-align: left;"><span><img width="329" height="142" alt="image" src="Image_155.gif"/></span></p><p style="padding-top: 9pt;padding-left: 226pt;text-indent: 0pt;text-align: left;">Figure 22-2. Response to <span class="s3">FIELDLOOK</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="nav">&nbsp;&nbsp;</p><p class="nav">&nbsp;</p><p class="nav"><a href="part129.htm">&lt; Previous</a><span> | </span><a href="../Medley-Primer.html">Contents</a><span> | </span><a href="part131.htm">Next &gt;</a></p><p class="nav">&nbsp;&nbsp;</p></body></html>