< Previous | Contents | Next >

Naming Variables and Records

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

environment from floppies when it contains several different programs, are two

examples that could, if you aren’t careful, provide a few problems. Here are a few tips on how to prevent problems:


• If you change the value of a system variable, MENUHELDWAIT for example, or connect to a directory other than {DSK}<LISPFILES> , write a function to reset the variable or directory to its original value. Run this function when you are finished working.

This is especially important if you change any of the system menus.


• Do not redefine Medley functions or CLISP words. Remember, if you reset an atom’s value or function definition at the top level (in the Executive Window), the message (Some.Crucial.Function.Or.Variable redefined) , appears. If this is not what you wanted, type UNDO immediately!

If, however, you reset the value or function definition of an atom inside your program, a warning message will not be printed.


• 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

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 BOUNDP . For

example, type:

(BOUNDP ’BackgroundMenu)


This atom is bound to the menu that appears when you press the leff mouse button

when the mouse cursor is not in any window. BOUNDP returns T. BOUNDP returns NIL

if its argument does not currently have a value.


• Make your function names as unique as possible. Once again, prefixing function

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. GETD is the Interlisp-D function that returns the function definition of an atom, if it has one. If an atom has no function definition, GETD returns NIL. For example, type:

(GETD ’CAR)

A non-NIL value is returned. The atom CAR already has a function definition.


• Use complete record field names in record FETCHes and REPLACE s when your code is not compiled. A complete record field name is a list consisting of the record

declaration name and the field name. Consider the following example:

(REC0RD NAME (FIRST LAST))

(SETQ MyName (create Name FIRST ’John LAST ’Smith)) (FETCH (NAME FIRST) OF MyName)

• Avoid reusing names that are field names of Lisp system records. A few examples of system records follow. Do not reuse these names.

(RECORD REGION (LEFT BOTTOM WIDTH HEIGHT)) (RECORD POSITION (XCOORD YCOORD))


(RECORD IMAGEOBJ (- BITMAP -)))


• When you select a record name and field names for a new record, check to see whether those names have already been used.


Call the function RECLOOK, 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

definition will be returned; otherwise the function will return NIL.


image


Figure 22-1. Response to RECLOCK


Call the function FIELDLOOK 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 NIL.


image

Figure 22-2. Response to FIELDLOOK