DEFINE







Syntax




   DEFINE  @name (1:)@word


Description




The DEFINE command creates symbol definitions. A symbol is a name that is associated with up to 128 characters, called its definition. Whenever a program finds a symbol, it replaces the symbol with its definitions.



Suppressing symbol evaluation



You can use the `@' character to suppress the evaluation of symbols.



Redefining keywords



Although it is perfectly legal, you should be careful about redefining keywords in commands. Redefining keywords can lead to commands that don't work t



Examples






Example 1



Although a symbol name must be a single word, it can represent any string of up to 128 characters. This means that most or all of a command can be stuffed into a single symbol, as shown in the examples below. This is the most typical, and most important, use of symbols.

   SET DEVICE IMAGEN_LANDSCAPE;
 
   DEFINE SKETCH     DRAW CLIP GRIDS STARS BORDER;
   DEFINE NEXT       SET TIME DELTA 60;
   DEFINE SP         SET PICTURE;
   DEFINE SA         SET AUTOERASE;
 
   SET POINTING SAT;
   SET VANTAGE EARTH;
 
   SA OFF;
 
   SP 1 OF 4;
   NEXT;
   SKETCH;
 
   SP 2 OF 4;
   NEXT;
   SKETCH;
 
   SP 3 OF 4;
   NEXT;
   SKETCH;
 
   SP 4 OF 4;
   NEXT;
   SKETCH;
 
   SA ON;


Example 2



You can use symbols to change the appearance of the command language for a program. For example, the definition

   DEFINE SEARCH FIND;
effectively changes the syntax of the FIND command. Given this definition, the FIND ECLIPSE command can be entered as

   SEARCH IO_ECL ECLIPSE OF IO BY JUPITER FROM EARTH;
Even though the symbol is longer than the definition, the command may now seem clearer, or easier to remember.



Example 3



You can use symbols to create parameterized procedures like the one shown below.

   ;
   ;  This procedure finds intervals when a given satellite is not
   ;  obscured by its primary planet. (That is, intervals when the
   ;  satellite is not occulted or eclipsed by the planet, and not
   ;  in transit across the planet.)
   ;
   ;  The symbols SATELLITE, PLANET, and OBSERVER,
   ;  STEPSIZE and OUTPUT_SCHEDULE
   ;  must be defined before executing the procedure.
   ;
   ;  The names OCC, ECL, TRN, and OBSCURED are used for temporary
   ;  schedules. The schedules are dropped at the end of the procedure.
   ;  Existing schedules with those names will be lost.
   ;
   FIND OCC OCCULTATION
        OF SATELLITE BY PLANET
        FROM OBSERVER
        STEP SIZE STEPSIZE;
 
   FIND ECL ECLIPSE
        OF SATELLITE BY PLANET
        FROM OBSERVER
        STEP SIZE STEPSIZE;
 
   FIND TRN TRANSIT
        OF SATELLITE ACROSS PLANET
        FROM OBSERVER
        STEP SIZE STEPSIZE;
 
   LET OBSCURRED = OCC + ECL;
   LET OBSCURRED = TRN + OBSCURRED;
 
   LET OUTPUT_SCHEDULE = OBSCURRED COMPLEMENT;
 
   ; Forget the temporary schedules OCC, ECL, TRN, and OBSCURED;
 
 
   FORGET SCHEDULE OCC;
   FORGET SCHEDULE ECL;
   FORGET SCHEDULE TRN;
   FORGET SCHEDULE OBSCURRED;


Example 4



Consider the following recursive definition.

   DEFINE ENVIRONMENT SHOW ENVIRONMENT;
The symbol ENVIRONMENT contains the word ENVIRONMENT as part of its definition. If not detected, PERCY would expand the command ENVIRONEMENT as

   SHOW ENVIRONMENT;
which is then translated again as:

   SHOW SHOW ENVIRONMENT;
and then again to

   SHOW SHOW SHOW ENVIRONMENT;
and so on. This kind of definition is called a recursive definition. Fortunately, Percy will not allow you to create such a definition. However, by using the '@' character to you can tell PERCY that a portion of the definition should not be processed during symbol expansion.

until it exceeds the maximum command size, at which time the program reports an error.

   DEFINE ENVIRONMENT @SHOW ENVIRONMENT@;
Using this definition, the command ENVIRONMENT expands as was intended when we defined it.



Notes




The INQUIRE command also defines symbols. The UNDEFINE command removes symbol definitions.

The current symbols and their definitions can be examined with the SHOW SYMBOL command.

The DEFINE and UNDEFINE commands always translate to blank commands. In echo mode, they are echoed as empty pairs of parentheses (see ECHO).



Related Topics




  1. Inquire
  2. Tailoring The Command Language
  3. The Percy Help System