The ADL Programmer's Reference Manual


Tim Brengle
Ross Cunniff


Hewlett-Packard Company Cupertino, California 95014

ABSTRACT

ADL (which stands for "Adventure Definition Language") is a programming language and run-time environment designed for the convenient implementation of Adventure-like games. This document describes ADL and is intended for the use of a programmer who wishes to create such a game.

The authors would like to acknowledge the tremendous influence of the earlier language DDL from which ADL was derived. DDL was created in 1981 by Bruce Adler, Chris Kostanick, Michael Stein, Michael Urban, and Warren Usui, then members of the UCLA Computer Club. For information on DDL, please consult the document "A Brief Description of UCLA Dungeon Definition Language (DDL)" written by the creators of DDL and available from the University of California.

June 19, 1987


Table of Contents

  1. Introduction
  2. ADL Data types
    1. Objects
    2. Verbs
    3. Adjectives
    4. Strings
    5. Numbers
    6. Routines
    7. Global Variables
    8. Local variables
    9. Modifiers
  3. ADL Internal Structures
    1. Actors
    2. Daemons
    3. Fuses
    4. Prompter
    5. Run-Time Macros
  4. Putting It All Together
    1. The Flow of Execution
    2. $exit
  5. ADL Programs
  6. Routines
  7. ADL Built-in Routines
    1. Object Routines
    2. Verb Routines
    3. Arithmetic Routines
    4. Boolean Routines
    5. Global Value Routines
    6. Transition Routines
    7. String Manipulation Routines
    8. Name Routines
    9. Conversion Routines
    10. Internal Structure Manipulation Routines
    11. Special Routines
    12. Miscellaneous Routines

1. Introduction

Computer games have existed for nearly as long as computers have existed. One of the most popular computer programs of all time is Adventure. In Adventure, the player is placed inside a world which exists only in the memory of the computer (and the mind of the player). The player interacts with this world by means of English-like sentences. Objects that the player finds may be taken, opened, closed, tasted, thrown, and otherwise manipulated.

Previously, most programmers attempting to write their own Adventure-like game have been bogged down by such trivial details as implementing a parser for player input, properly responding to the player's commands, and dealing with the passage of time. ADL is intended to relieve the programmer of such worries and to allow the programmer to concentrate on the important details of the imaginary world. The following is a short excerpt from the play of a game which was written in ADL:

     Red room.
     You are in	a large	room which is illuminated by a bright red glow.
     Exits lie to the east and south.
     > Go east.
     Green room.
     You are in	a smallish room	which is illuminated by	a pleasant green
     glow.  The	only exit is to	the west.
       There is	a robot	here.
     > west
     Red room.
     > s
     Blue room.
     You are in	a tiny room which is barely illuminated	by a dim blue
     glow.  There is an	exit to	the north, and you seem	to make	out
     something on the floor.  There is a button	on the wall.  Above the
     button is a sign that reads:

		     DANGER!

		  HIGH VOLTAGE!

     > n
     Red room.
     > e
     Green room.
     You can see:
       a robot
     > Tell the	robot "Go west then south.  Push the button then go north."
     "Sure thing, Boss."
     The robot exits to	the west.

Notice that this script demonstrates powerful features not present in many other Adventure-like games. This document will describe the utilities and "tricks" necessary to write games such as the above.


2. ADL Data types

Structured data types are the heart of any structured language. ADL is not lacking in structured data types. It is through the proper definition of specific instances of these data types that the ADL programmer defines a scenario. Note that all data types in ADL are represented by sixteen-bit integer IDs. Although there is little facility for producing user-defined data types, the power of the existing set makes it unlikely that such would be required for any reasonable scenario.

2.1. Objects

As in most Adventure-like games, the most important data type in ADL is the Object. An object in real life can be a person, place, or thing. ADL models the world in the same way. Any Object encountered by the player is represented by this type, as are all locations in the scenario. Indeed, there can be Objects associated with people (more on that later). Notice that ADL treats all Objects uniformly and so it is possible to write a scenario in which a player picks up an Object (a tent, say), carries it around, and later enters it.

All Objects are represented by (unique) sixteen-bit integers. This number is known as the "Object ID" of the Object. Objects are (essentially) record structures with the following elements:

Location
The Object ID of the Object which contains this Object.
Contents
The Object ID of the first Object which is contained in this Object, or zero if there is no such Object.
Link
The Object ID of the next Object which is located in the same place as this Object or zero if there is no such Object.
Modifier
The ID of the modifier of this Object or zero if the Object has no modifier. For example, the Object "blue streak" would have a modifier ID which is the adjective "blue". Modifiers are explained further in Section 2.9.
Properties
Associated with each Object are 32 properties. While all of the above elements are maintained directly or indirectly by the ADL system, the values and meanings of properties are the responsibility of the programmer. The first 16 of these properties may only hold the value 0 or 1 (hence they are usually called "boolean" properties). Properties 17 through 32 may hold any value between -32768 and 32767. The last three of these properties have special meaning to ADL:
LDESC (30)
This is the ID of a routine which prints a "long" description of the Object. Routines are defined in Chapter 6.
SDESC (31)
This is the ID of a routine which prints a "short" description of the Object.
ACTION (32)
This is the ID of a routine which is called under the circumstances detailed in Chapter 4.

All Objects in ADL are stored in a tree. The root node of the tree is predeclared and is named ".ALL". Its Object ID is always zero. All other Objects are ultimately located in .ALL.

Two other predeclared Objects exist. One is named "STRING" and the other is named ".ME". .ME is not truly an Object -- it is more like a variable which represents the current Actor during the execution of an ADL program (more on Actors in Section 3.1). It is illegal to use .ME outside of the context of a routine. STRING is the Object which is seen by the ADL program when the run-time sentence parser encounters a string. Note that although STRING is predeclared by ADL, the properties of STRING must be defined by the ADL programmer. See Chapter 9 for more information on STRING.

2.2. Verbs

Verbs are the means whereby a player manipulates the environment. Verbs can denote motion, investigation, manipulation, and any other action the ADL programmer can imagine. A Verb is represented by a sixteen-bit integer known as the Verb ID. Like Objects, Verbs are record structures. They have the following elements:

PREACT
The ID of a routine to be called when this Verb is typed by the player. The routine is called before the ACTION routines of the Objects in the sentence. See Chapter 4 for more information.
ACTION
The ID of a routine to be called when this Verb is typed by the player. This routine is called after the ACTION routines of the Objects in the sentence. Again, see Chapter 4 for more information.

Verbs may also be used as modifiers to nouns. This is to allow easy implementation of Objects like the "north wall" or "go north" (where "north" is normally a verb of motion).

ADL predeclares the two Verbs "TELLER" and "NOVERB" which are returned by the parser under circumstances shown in Chapter 9. Although TELLER and NOVERB are predeclared, their properties must be defined by the ADL programmer.

2.3. Adjectives

Adjectives serve only one purpose: to disambiguate otherwise identical nouns (such as a "red ball" and a "blue ball"). Adjectives have no structure and exist only as sixteen-bit Adjective IDs.

2.4. Strings

There are two forms of strings in ADL: compile-time strings and run-time strings. Compile-time strings are those which appear in the ADL source code for the scenario. They are delimited by double quotes and are transformed into positive sixteen-bit String IDs by the compiler. These strings are free-form in that a carriage return may appear in them at any point. This sort of carriage return is transformed into a blank. Should the ADL programmer desire a true carriage return, the sequence \n should be embedded in the string at the appropriate point. Compile-time strings may be limited to 255 characters in length in some implementations.

Run-time strings are those which are typed by the player and those which are generated by the built-in string manipulation routines. Strings in player input may be delimited by appropriately nested single or double quotes. All run-time strings are represented as NEGATIVE sixteen-bit string IDs.

2.5. Numbers

There are two forms of numbers in ADL: compile-time numbers and run-time numbers. Compile-time numbers exist in the ADL source code for the scenario and may be any integer in the range of -32768 to 32767 inclusive. Run-time numbers are those which are typed by the player. Run-time numbers are transformed into a string consisting of the ASCII representation of their digits. A negative string ID is then returned for eventual use by the ADL program.

2.6. Routines

Routines in ADL are represented by (what else?) sixteen bit Routine IDs. The only operations allowed on routines are calling them and passing them to other routines as parameters. The syntax of ADL routines is described in Chapter 6. The routine "START" is predeclared by ADL and must be defined by the programmer or execution will be prematurely terminated. The Routines "DWIMI" and "DWIMD" are also predeclared by ADL and should be defined by the programmer. DWIMI and DWIMD are called under circumstances detailed in Chapter 4.

2.7. Global Variables

There are a number of global variables available for definition and use by the ADL programmer. A global is represented by a sixteen-bit ID and may hold any integer value from -32768 to 32767. These values may be interpreted as simple numbers, String IDs, Routine IDs, Object IDs, Verb IDs, etc. depending upon how they are used. The globals named Verb, Conj, Numd, Dobj, Prep, and Iobj are predeclared by ADL and at run-time contain the values of the current Verb, Conjunction, Number of Direct Objects, Direct Object, Preposition, and Indirect Object, respectively.

The ADL programmer may declare a block of global variables for use as an array or list of things. See Chapter 5 for more information.

2.8. Local variables

Local variables differ from global variables in that their name is limited in scope to the routine in which they appear. They are represented by sixteen-bit IDs which may be passed to other routines if desired. Local variables may be implemented in one of two ways: on the stack (like local variables on C and Pascal) in which case they are only around for as long as the current invocation of the routine; or they may reside in the same space as global variables (like static locals in C or local variables in FORTRAN) in which case they persist for the entire duration of program execution. Consult your local ADL documentation to determine which method is used in your implementation.

2.9. Modifiers

A modifier is simply a word that modifies an ambiguous noun to produce an Object. A modifier may be either a Verb or an Adjective. If the modifier of an Object is a Verb, it is represented as the NEGATIVE of the Verb ID. If it is an Adjective it is represented by the (positive) Adjective ID. If the modifier is zero, the Object has no modifier.


3. ADL Internal Structures

ADL maintains several internal structures to achieve the level of interaction necessary for interesting play. These structures are accessible only through the built-in routines described in Chapter 7.

3.1. Actors

In a typical adventure game it seems as if the player is moving around the dungeon taking things, smelling them, breaking them, and so on. A better model would be that the player is giving commands to an actor. It is the actor which actually moves around, collects items, and otherwise acts. It is this model which ADL follows.

An Actor is essentially an "animate" object which acts upon commands given to it. Notice that there is nothing in this model which prevents more than one Actor from running around a scenario. In fact, in ADL there may be up to ten Actors which are active at any one time.

There are two kinds of Actors: interactive and non-interactive. The player is an example of an interactive Actor. Commands are read directly from the keyboard and placed in a line buffer which is then passed to the parser and interpreter. When the line buffer is empty a new one is read from the keyboard. Any number of Actors may be interactive, making multiple player games a possibility.

The robot in the introductory script is an example of a non-interactive Actor (see Appendix 2 for the source to the scenario which produced that script). The line buffer for the robot was initialized after the player typed the sentence starting with "Tell the robot ...". The robot then acted on this command by performing the requested actions in parallel with the actions of the player. This means that each Actor gets one turn for each turn that the player experiences. A non-interactive Actor is deleted from the list of active Actors when its line buffer is emptied.

There is a special object-like item named ".ME" used to implement this sort of "multiprocessing". .ME represents the Object ID of the current Actor for the purposes of moving around, taking things, etc. Anything that the player can do can be done just as well by another Actor. This is probably the most powerful (and most obscure) feature of ADL.

Actors may be activated using the $actor built-in routine and deleted at any time by using the $delact routine.

3.2. Daemons

Daemons are routines which execute once for each active Actor at the beginning of each turn. Daemons are typically used for things like describing the player's location and incrementing the turn counter. Daemons are activated by using the $sdem routine and may be de-activated by using the $ddem routine. Up to ten daemons may be active at one time.

3.3. Fuses

Fuses are routines which wait a certain amount of time, execute, then become inactive. The list of fuses is examined each time the turn counter is incremented to see whether any have "burned down". If so, the fuse is executed and deleted from the list.

Fuses are typically used for things like waiting three turns and then collapsing the room that the player was in, or (the bane of all adventurers) running down the batteries in a lamp. Fuses are activated by using the $sfus routine. Up to ten fuses may be active at one time. The $dfus routine may be called if the programmer wishes to delete a fuse before it executes (the player found more batteries!).

3.4. Prompter

Many times during the play of the game it is desired that a player enter a line from the keyboard. Some sort of prompting should be done in order to inform the player that input is desired. The ADL programmer may specify a Routine ID to do this prompting. This routine is known as the prompter and is set by using the $prompt routine.

3.5. Run-Time Macros

Normally when the parser gets its input from the line buffer of the current Actor, the words are what they seem to be: simple words. ADL has a facility whereby these words may be transformed before the parser sees them. Each word is looked up in a table (the "macro table"). If found it is replaced by the expansion for the macro (which may be a string containing more than one word) and re-inserted into the line buffer whereupon the input process continues.

One use of this facility is to "rename" objects. For example, it may be desired that the player be able to type something like "Name the box 'bob'. Take bob." (notice that the second usage of bob has no quotes). This can be accomplished by the call ($define "bob" "box") which says to expand "bob" to "box" whenever it is encountered in the line buffer. The built-in routine $undef may be used to "undefine" a macro if it outlives its usefulness -- for example ($undef "bob") removes "bob" from the macro table. More is said about macros in Section 7.10 under the entries for $define and $undef.


4. Putting It All Together

The flow of execution of the game can be described now that the basic data types have been defined. The execution starts with an initialization step: an ADL routine named START is called. ADL terminates prematurely if START has not been defined. START typically activates the principal Actor (the player) and a looker daemon (responsible for describing the player's surroundings), initializes the prompter, and so on. ADL then enters a loop from which it never returns (until program termination).

4.1. The Flow of Execution

The main loop of the game consists of a series of phases. The built-in routine $phase will return the number of the phase currently executing (see the flow diagram and Section 7.12 for the number of each of the phases). At the beginning of each turn, all active Daemons are executed for each Actor on the Actor list -- in the REVERSE order in which the Actors were activated. This is so newly activated Actors don't act before the older Actors have a chance to act. The Daemons are executed in the order in which they were activated.

After all Daemons have executed for all Actors, a series of phases are executed for each Actor on the Actor list (in the reverse order of Actor activation). The loop progresses downward in an orderly fashion unless interrupted by a call to $exit. For information on $exit see Section 4.2. The following are the phases which are executed for each Actor on the Actor list:

Clear Sentence
The global variables Verb, Conj, Numd, Dobj, Prep, and Iobj are set to 0. This is done in a separate phase to facilitate the implementation of incremental sentences such as "Take. The red ball."
Input
A new line buffer is prompted for and read if the line buffer is empty and the current Actor is interactive.
The current Actor is deleted from the Actor list and execution continues starting with the next Actor if the line buffer is empty and the current Actor is NOT interactive.
Parse
All upper case letters in the line buffer are transformed into lower case letters. An attempt is then made at parsing the line buffer into a Verb, Direct Objects, a Preposition, and an Indirect Object. Note that unambiguous abbreviations of words are recognized by the parser (for example, if the words "newt" and "newspaper" are in the vocabulary, "new" is ambiguous but "news" is an abbreviation of "newspaper"). An appropriate message is printed if this does not succeed and execution continues from the Input phase.
ADL sentences are typically of the form "Verb DobjList Prep Iobj" "Verb Iobj DobjList", or "Iobj, String". This is an overly simplistic description - for a full specification see Chapter 9.
DWIM
An object may be ambiguous either through the lack of a modifier or through the use of a modifier without a noun (e.g. typing "Take the ball" when there is both a "red ball" and a "blue ball", or typing "Take red" in the same situation).
An ADL routine named "DWIMI" is used if the Indirect Object is ambiguous. DWIMI is called once for each Object that could possibly be the one meant by the player. If EXACTLY one of these calls returns a non-zero value then the corresponding Object becomes the Indirect Object. However, if DWIMI never returns a non-zero value or if it returns a non-zero value more than once, the player is told to be more specific and execution continues starting with the Clear Sentence phase above.
An ADL routine named "DWIMD" is used if any of the Direct Objects are ambiguous. DWIMD is called for the Objects in question just like DWIMI.
Execution
The following phases are executed for every Direct Object in the Direct Object list. They are executed exactly once if there are no Direct Objects. This loop is the heart of the ADL system and is where the player's commands are actually carried out.
Actor ACTION
The ACTION routine of the current Actor is executed. It typically checks the sentence and possibly modifies it. This allows the handling of cases like "Take the beer then drink it" (where "it" needs to be massaged to mean "beer") and "Go north. Again." (where "Again" needs to be transformed into "Go north").
Verb PREACT
The PREACT routine of the current Verb is exe- cuted. It typically guards against incorrect use of multiple Direct Objects, or the use of Indirect Objects or strings where such use doesn't make sense. It also might check that all objects named are available for use.
Iobj ACTION
The ACTION routine of the current Indirect Object is executed. This is where some object-specific actions are performed. For example, the sentence "Put the coins in the slot" might be handled here if putting coins into the slot (as opposed to a box or a bag) causes something special to happen. If the Indirect Object is a string then the ACTION routine of the predeclared ADL Object named STRING is executed.
Dobj ACTION
The ACTION routine of the current Direct Object is executed. This is where most object-specific actions are performed. For example, the sentence "Rub the lamp" might be handled here if rubbing the lamp is different than rubbing any other Object. The ACTION routine of the predeclared ADL Object STRING is executed if the Direct Object is a string.
Verb ACTION
The ACTION routine of the current Verb is executed. This is where general default actions are usually handled. For example, the sen- tence "Rub the floor" might result in the message "Rubbing that object is not useful."
Room ACTION
The ACTION routine of the current Actor's location is executed once the above loop has examined all of the Direct Objects. This routine is typically a "transition" routine -- that is, it might check whether the current verb is "north" and move the current actor to the appropriate location (it might check other directions as well!).

4.2. $exit

It is possible to change the normal flow of execution by means of the $exit built-in routine. The programmer may use ($exit 0) to halt execution of the current phase and move on to the next phase. At any time, ($exit 1) may be used to halt the execution of the current phase and skip to the next Actor. Inside the Direct Object loop, ($exit 2) may be used to skip the rest of the Object and Verb ACTIONs and go on to the next Direct Object in the list. At any time after the parsing phase, ($exit 3) will return the flow of control to the Parsing phase without clearing the sen- tence. This allows for incremental entry of sentences; for example "The big door. Unlock. With the key".

     The following is a	diagram	of the flow of execution:


					   START [0]
					     |
					     v
	  +--------------------------------->o
	  |				     |
	  |				     v
	  |				  Daemons [1]
	  |				     |
	  |				     v
	  |				 Get Actor <----------------------+
	  |				     |				  |
	  |				     v				  |
	  |	  +------------------> Clear Sentence			  |
	  |	  |			     |				  |
	  |	  |			     v				  |
	  |	  |	  ($exit 3)====> Get Input? --n---> Delete Actor  |
	  |	  |			     | y		  |	  |
	  |	  |			     v			  |	  |
	  |	  o<---------------------- Parse?		  |	  |
	  |	  ^			     |			  |	  |
	  |	  |			     v			  |	  |
	  |	  o<-------------fail----- DWIMI		  |	  |
	  |	  ^			     |			  |	  |
	  |	  |			     v			  |	  |
	  |	  +--------------fail----- DWIMD		  |	  |
	  |				     |			  |	  |
	  |				     v			  |	  |
	  |				 Get Dobj <-------+	  |	  |
	  |				     |		  |	  |	  |
	  |				     v		  |	  |	  |
	  |			       Actor ACTION [2]	  |	  |	  |
	  |				Verb PREACT [3]	  |	  |	  |
	  |				Iobj ACTION [4]	  |	  |	  |
	  |				Dobj ACTION [5]	  |	  |	  |
	  |				Verb ACTION [6]	  |	  |	  |
	  |				     |		  |	  |	  |
	  |				     v		  |	  |	  |
	  |		  ($exit 2)===>	More Dobjs? -y----+	  |	  |
	  |				     | n		  |	  |
	  |				     v			  |	  |
	  |				Room ACTION [7]		  |	  |
	  |				     |			  |	  |
	  |				     v			  |	  |
	  |		  ($exit 1)=========>o<-------------------+	  |
	  |				     |				  |
	  |				     v				  |
	  +--------------------------n-	More Actors? -y-------------------+


5. ADL Programs

This chapter describes the format of ADL programs. An ADL program consists of a list of one or more of the following statements. Comments in ADL programs are delimited by { and }. Since case is significant in ADL, tokens which are identical except for differing case are different (for example, "noun" is not the same as "NOUN").

Note: for a full BNF specification of ADL programs, see Chapter 8.

INCLUDE "filename";
Input to the ADL compiler is read from filename until the end of file and compilation then resumes from the current file. A file included in compilation by means of an INCLUDE statement may INCLUDE other files.
	Example:
		     INCLUDE "standard.adl";
MESSAGE "message";
The string message is printed on the console at compile time. This is used to remind the programmer of things which should be initialized or to simply reassure the programmer that the compiler is indeed reading the file.
	Example:
		     MESSAGE "Whew!  We're halfway through the file!\n";
VAR name, name, ... ;
This declares each name to be a new global variable. The contents of global variables are initialized to zero. Each name must not have been previously declared. Each name may be followed by a size specifier, in which case that number of words is allocated. As ADL routines have no specific facilities for handling arrays, it is the responsibility of the ADL programmer to add the desired offset to the base of the array in order to access an element of the array For example, ($setg ($plus Array 10) 5) is similar to Array[ 10 ] = 5 in C.
	Example:
		     VAR
			     Score,
			     Dark,
			     ObjList[ 10 ],
			     MyLoc;
LOCAL name, name, ... ;
This statement is only legal inside routine definitions. It declares each name as a new Local Vari- able. Each name may or may not already have been declared. If a name is the same as the name of something declared outside the routine, that thing cannot be directly referenced by the routine. The name of a local variable is only visible to the routine in which it is defined. Local variables may be arrays just as global variables may. Note that a routine may have a maximum of 32 words of local variables. Arrays of local variables use up that space rather quickly, so they should be used with care. See the next chapter for an example using local variables.
VERB name, name, ... ;
This statement declares each name to be a new Verb. The PREACT and ACTION routines of Verbs are initialized to zero. Each name must not have been previously declared.
	Example:
		     VERB    take, drop, open, close;
ADJEC name, name, ... ;
This statement declares each name to be a new Adjective. Again, each name must not have been previously declared.
	Example:
		     ADJEC   red, green, blue;
NOUN ndecl, ndecl, ... ;
This statement declares Objects. Ndecl may take the form obj or obj ( container ). The first form declares a new Object located in the object .ALL. The second form declares a new Object located in container. Each obj may be one of: an undeclared identifier, a modifier followed by an undeclared identifier, or a modifier followed by a previously declared noun. If obj is just an undeclared identifier, the identifer is declared to be a noun and a new Object is created with that noun ID and with a modifier of 0. If obj is a modifier followed by an undeclared identifier, the identifier is declared to be a noun and a new Object is created with that noun ID and with the modifier set to the one specified. If obj is a modifier followed by a previously declared noun, a new Object is created with the specified noun ID and the specified modifier. Note that the declaration "NOUN foo, blue foo;" is illegal since it would be too easy to create situations where the player is unable to disambiguate the Objects.
	Example:
		     NOUN    room1;
		     NOUN    table( room1 ), chair( room1 ), red ball( room1 );
ROUTINE name, name, ... ;
This statement declares each name to be a new routine. Note that this does not associate a routine with the Routine ID -- it just declares the routine. This is useful for daisy-chaining routines (i.e. routine A calls routine B, which calls routine A) since everything must be declared before it is used. Each name must not have been previously declared.
	Example:
		     ROUTINE Looker, Prompter, Quitter;
ARTICLE name, name, ... ;
This statement declares each name to be a new Article. Each name must not have been previously declared.
	Example:
		     ARTICLE the, a, an;
PREP name, name, ... ;
This statement declares each name to be a new Preposition. Each name must not have been previously declared.
	Example:
		     PREP    in, into, on, above ;
obj (const) = expr ;
This statement assigns property const of obj to be expr. Const must be a number or the name of a constant (see below). Expr may be a string, a number, a routine, another noun, or just about anything else which yields a sixteen bit ID. Obj must be previously declared. A warning may be produced if this particular property is reassigned later in the program.
	Example:
		     room1( LDESC ) =
			     ($say "You	are in a huge room.\n")
		     ;
		     chair( WEIGH ) = 450 ;
		     table( MESSAGE ) =	"This space for	rent\n"	;
verb (const) = routine ;
This statement assigns property const of verb to be routine. Const must be either PREACT or ACTION, and verb must have been previously declared. A warning may be produced if this particular property is reas- signed later in the program.
	Example:
		     take( ACTION ) = ($say "You can't take that object.\n");
		     drop( PREACT ) = (CheckAvail);
name = expr;
This statement declares that name is equivalent to expr. Name must not have been previously declared and expr may be an object, a string, a routine, a number, or just about anything else that yields a sixteen-bit value.
	Example:
		     MagicWord = "AbraCadabra";	     { string ID }
		     VISIT = 3;				     { constant	}
		     Silly = ($say "That's silly!\n");	     { routine ID }
		     toolbox = tool box;		     { object ID }
(global) = expr;
This statement initializes global variable global to have the value expr. Global must have been previously declared and expr is the same as expr above.
	Example:
		     ( MyLoc ) = -1;
		     ( Score ) = 10;

(global + const) = expr;
This statement initializes the const'th slot in the global array global to have the value expr.
	Example:
		     VAR foo[ 10 ];
		     ( foo ) = 3;	     { Sets foo[0] to 3	}
		     ( foo + 5 ) = 6;	     { Sets foo[5] to 6	}
prep1 obj prep2 = prep3;
This statement declares that if the three-word sequence prep1 obj prep2 is encountered during run- time parsing in the proper position for a preposition, it is to be replaced by prep3. Obj may be a modifier-noun pair and prep1, prep2, and prep3 must have been previously declared.
	Example:
		     PREP
			     in, of, before;
		     NOUN
			     front;

		     in	front of = before;
verb1 prep = verb2;
This statement declares that if the two-word sequence verb1 prep is encountered during run-time parsing in the proper position for a verb, it is to be replaced by verb2. Verb1, verb2, and prep must have been previously declared.
	Example:
		     VERB
			     put, take,	turn, wear, remove, light, douse;
		     PREP
			     on, off;

		     put on = wear;
		     take off =	remove;
		     turn on = light;
		     turn off =	douse;

6. Routines

This chapter describes the syntax of ADL routines. An ADL routine consists of an optional LOCAL declaration fol- lowed by a sequence of one or more expressions. An expression is one of the following:

Routine call
A routine call in ADL takes the form (rout arglist). Rout is either the name of a built-in routine, the name of a user routine, or an expression which evaluates to a Routine ID. Arglist is a list of zero or more args each of which is one of:
An expression
A simple expression
A simple expression is one of a string, a number, or a name which was declared as in Chapter 5.
@global
This is interpreted to mean "the contents (or value) of global".
%number
This is interpreted to mean "the numberth argument to this func- tion". Note that %0 is the number of arguments passed to this function.
[ modif noun ]
This construct must be used if the programmer wants to use the value of an Object which has a modifier.

The value of the expression is the result of executing rout with arguments arglist.
Conditional
A conditional expression takes the form
		   ( IF	arg1 THEN expression ...
		     ELSEIF arg2 THEN expression ...
			   ...
		     ELSE expression ...  )
This statement evaluates arg1 and if the result is non-zero the expressions following THEN are executed. If the result of the evaluation of arg is zero then the expressions following THEN are skipped until one of ELSE, ELSEIF or the end of the conditional are found. If ELSEIF was found the corresponding arg is evaluated and execution proceeds as for IF. If none of the ELSEIFs evaluate to a non-zero value then the ELSE expressions are executed. The ELSEIFs and the ELSE are optional. The conditional expression returns the value of the last expression executed or zero of no expressions were executed.
Loop
A loop takes the form ( WHILE arg DO expression ... ). If arg evaluates to a non-zero value then the expressions are evaluated. This process repeats until arg evaluates to zero. This statement always returns zero.
Example
On the following page is a sample ADL routine which demonstrates each of the above con- structs and is almost useful as well See Chapter 7 for the definitions of the built-in routines called.
		   { A sample looking daemon }
		   Look	=
		   LOCAL obj;
			   ($incturn)	   { Increment the turn	counter	}
			   (IF ($prop ($loc .ME) VISIT)	THEN
			   { I've been here before - print a short description }
				   ( ($sdesc ($loc .ME)) )
			    ELSEIF ($ne	($cont ($loc .ME)) .ME)	THEN
			   { There are other objects here }
				   ( ($ldesc ($loc .ME)) )
				   ($say "You can see:\n")
				   ($setg obj ($cont ($loc .ME)))
				   (WHILE @obj DO
					   { Describe each object in the room }
					   ( ($sdesc @obj) )
					   ($setg obj ($link @obj))
				   )
			    ELSE
			    { I've never been here }
				   ( ($ldesc ($loc .ME)) )
				   ($say "There	is nothing else	in the room.\n")
			   )
			   ($setp ($loc	.ME) VISIT TRUE)
		   ;

7. ADL Built-in Routines

The following is the complete list of ADL built-in routines. They are organized into groups of related routines. A description of each routine is provided with at least one example to clarify its usage. The following groupings of built-in routines are detailed in this chapter:

7.1 Object Routines
7.2 Verb Routines
7.3 Arithmetic Routines
7.4 Boolean Routines
7.5 Global Value Routines
7.6 Transition Routines
7.7 String Manipulation Routines
7.8 Name Routines
7.9 Conversion Routines
7.10 Internal Structure Manipulation Routines
7.11 Special Routines
7.12 Miscellaneous Routines

7.1. Object Routines

These routines operate primarily on Objects. They move Objects around, find Object properties, and set Object properties.

$loc
( $loc obj ) -> The location of obj.
	Example:
		     (IF ($eq ($loc .ME) volcano) THEN
			     ($say "You	are fried to a crisp.\n")
		     )
$cont
( $cont obj ) -> The first object which is contained in obj.
	Example:
		     (IF ($eq ($cont .ME) 0) THEN
			     ($say "You	are empty-handed.\n")
		     )
$link
( $link obj ) -> The next object contained in the same location as obj.
	Example:
		     ($setg obj	($cont .ME))
		     (WHILE @obj DO
			     ($say ($name @obj)	"\n")
			     ($setg obj	($link @obj))
		     )
$ldesc
( $ldesc obj ) -> The long description of obj. This is equivalent to ($prop obj LDESC). Since this is a Routine ID, it is typically used as the callee in a routine call.
	Example:
		     ($setg obj	($loc .ME))
		     ( ($ldesc @obj) )	{ Call LDESC of	($loc .ME) }
$sdesc
( $sdesc obj ) -> The short description of obj. This is equivalent to ($prop obj SDESC). Since this is a Routine ID, it is typically used as the callee in a routine call.
	Example:
		     ($setg obj	($loc .ME))
		     ( ($sdesc @obj) )	{ Call SDESC of	($loc .ME) }
$action
( $action obj ) -> The ACTION routine of obj. This is equivalent to ($prop obj ACTION). Since this is a Routine ID, it is typically used as the callee in a routine call.
	Example:
		     ( ($action	.ME) )	{ Call ACTION of .ME }
$modif
( $modif obj ) -> The modifier of obj. This is zero if there is no modifier, negative if the modifier is a Verb, and positive if the modifier is an Adjective.
	Example:
		     (IF ($eq ($modif [	blue ball ] ) blue) THEN
			     ($say "$modif works!\n")
		     )
		     (IF ($eq ($modif [	north wall ] ) ($minus 0 north)) THEN
			     ($say "$modif still works!\n")
		     )
		     (IF ($eq ($modif room1) 0)	THEN
			     ($say "$modif comes through one more time!\n")
		     )
$prop
( $prop obj num ) -> The numth property of obj.
	Example:
		     ($setg obj	($loc .ME))
		     (IF ($prop	@obj VISIT) THEN
			     ($say "I've been here before!\n")
		     )
$setp
( $setp obj num val ) -> No return value. Sets the numth property of obj to val.
	Example:
		     ($setg obj	($loc .ME))
		     ($setp @obj VISIT TRUE)
$move
( $move obj loc ) -> No return value. Moves obj to loc. WARNING: Do not attempt to violate the tree structure of objects (e.g. ($move .ALL foobar)) or horrible and unpredictable things will happen.
	Example:
		     (IF ($eq @Verb north) THEN
			     ($move .ME	room2)
		     )

7.2. Verb Routines

These two routines operate on Verbs. They are provided for scenarios in which the properties of Verbs may change.

$vset
( $vset verb prop val ) -> No return value. The pro- perty prop of verb is set to val. Prop must be either PREACT or ACTION.
	Example:
		     ($vset @Verb PREACT Silly)
$vprop
( $vprop verb prop ) -> The value of property prop of verb. Prop must be either PREACT or ACTION.
	Example:
		     { Call Verb's PREACT }
		     ( ($vprop @Verb PREACT) )

7.3. Arithmetic Routines

These routines operate on arbitrary sixteen-bit numbers, and return sixteen-bit values. Note that the numbers may actually be Object IDs, global variable IDs, or any of the sixteen bit IDs used by ADL.

$plus
( $plus num1 num2 ) -> Returns num1 + num2.
	Example:
		     ($setg Score ($plus @Score	50))
$minus
( $minus num1 num2 ) -> Returns num1 - num2.
	Example:
		     ($setg LivesLeft ($minus @LivesLeft 1))
$times
( $times num1 num2 ) -> Returns num1 * num2.
	Example:
		     ($setg TimeLeft ($times @NumBattery 10))
$div
( $div num1 num2 ) -> Returns num1 / num2.
	Example:
		     ($setg Rating ($div @Score	100))
$mod
( $mod num1 num2 ) -> Returns the remainder which results when num1 is divided by num2 according to normal integer division.
	Example:
		     { Make sure XPos is from 0	to 9 }
		     ($setg XPos ($mod @Xpos 10))
$rand
( $rand num ) -> Returns a random number from 1 to num inclusive.
	Example:
		     { Move the	player to a random room	from room1 to room10 }
		     ($setg Num	($rand 10))
		     ($move .ME	($plus room1 ($minus @Num 1)))

7.4. Boolean Routines

These routines are typically used in conditionals and loops. However, traditional bit-masking may be done with $and and $or.

$and
( $and a b c ... ) -> Returns the bitwise AND of the vector a b c .... Note that since this is the bit-wise AND, care must be taken in conditions since ANDing two non-zero values does not necessarily return a non-zero value.
	Example:
		     ($and 2 4)	is 0 (0b0001 AND 0b0010	= 0b0000)
		     ($and 3 7)	is 3 (0b0011 AND 0b0111	= 0b0011)
		     ($and 1 1)	is 1 (0b0001 AND 0b0001	= 0b0001)
$or
( $or a b c ... ) -> Returns the bitwise OR of the vector a b c ....
	Example:
		     ($or 0 0) is 0  (0b0000 OR	0b0000 = 0b0000)
		     ($or 1 2) is 3  (0b0001 OR	0b0010 = 0b0011)
		     ($or 1 1) is 1  (0b0001 OR	0b0001 = 0b0001)
$not
( $not num ) -> Returns zero if num is non-zero and one if num is zero. Note that this is BOOLEAN NOT and not BITWISE NOT. BITWISE NOT could be coded as ($minus ($minus 0 %1) 1) for a two's complement machine.
	Example:
		     ($not 0) is 1
		     ($not 1) is 0
		     ($not 5) is 0
$yorn
( $yorn ) -> Waits for the player to type a line of input, returns one if this line begins with the letter 'Y' or 'y', and returns zero otherwise. Note that no prompt is automatically made for this input.
	Example:
		     ($say "Are	you sure you want to quit? ")
		     (IF ($yorn) THEN
			     ($say "OK.	 Goodbye!\n")
			     ($spec 3)
		      ELSE
			     ($say "Whew! That was a close one!\n")
		     )
$pct
( $pct num ) -> Returns one num percent of the time and zero the rest of the time. This is equivalent to ($ge num ($rand 100)).
	Example:
		     (IF ($pct 30) THEN
			     ($say "The	troll swings at	you, and hits!\n")
		      ELSE
			     ($say "The	troll's	axe misses you by a hair!\n")
		     )
$eq
( $eq num1 num2 ) -> Returns one if num1 is equal to num2 and zero otherwise.
	Example:
		     ($setg loc	($loc .ME))
		     (IF ($eq @loc room1) THEN
			     ($say "You	are in room 1.\n")
		     )
$ne
( $ne num1 num2 ) -> Returns one if num1 is not equal to num2 and zero otherwise.
	Example:
		     ($setg loc	($loc .ME))
		     (IF ($ne @LastLoc @loc) THEN
			     ($say "You've moved since I last checked!\n")
		     )
$lt
( $lt num1 num2 ) -> Returns one if num1 is less than num2 and zero otherwise.
	Example:
		     (IF ($lt @Score 100) THEN
			     ($say "You	are a novice adventurer\n")
		     )
$gt
( $gt num1 num2 ) -> Returns one if num1 is greater than num2 and zero otherwise.
	Example:
		     (IF ($gt @Score 1000) THEN
			     ($say "You	are a super master grand ")
			     ($say "champion mongo adventurer!!!\n")
		     )
$le
( $le num1 num2 ) -> Returns one if num1 is less than or equal to num2 and zero otherwise.
	Example:
		     (IF ($le @Score 1000) THEN
			     ($say "You	are a pretty good adventurer.\n")
		     )
$ge
( $ge num1 num2 ) -> Returns one if num1 is greater than or equal to num2 and zero otherwise.
	Example:
		     (IF ($ge @Weight 200) THEN
			     ($say "The	ice breaks under your weight!\n")
		     )

7.5. Global Value Routines

$setg
( $setg which val ) -> Returns val. Sets the con- tents of (or the value of) variable which to be val.
$global
( $global which ) -> Returns the contents of (or the value of) variable which. Equivalent to @which, with the exception that $global allows arithmetic expressions.
	Example:
		     Given:
			     VAR var[3];
			     (var + 0) = 10;
			     (var + 1) = 20;
			     (var + 2) = 30;

		     The statement
			     ($global ($plus var 2))
		     would return 30.
$verb
( $verb ) -> Returns the current Verb. Equivalent to @Verb.
	Example:
		     (IF ($eq ($verb) take) THEN
			     ($say "You	can't take that!!\n")
		     )
$dobj
( $dobj ) -> Returns the current direct object. Equivalent to @Dobj.
	Example:
		     (IF ($eq ($dobj) ball) THEN
			     ($say "Dobj = ball\n")
		     )
$iobj
( $iobj ) -> Returns the current indirect object. Equivalent to @Iobj.
	Example:
		     (IF ($eq ($iobj) basket) THEN
			     ($say "Iobj = basket\n")
		     )
$prep
( $prep ) -> Returns the current Preposition. Equivalent to @Prep.
	Example:
		     (IF ($eq ($prep) into) THEN
			     ($say "Prep = into\n")
		     )
$conj
( $conj ) -> Returns the current conjunction. Equivalent to @Conj.
	Example:
		     (IF ($eq ($conj) 1) THEN
			     ($say "The	conjunction was	'but'\n")
		      ELSE
			     ($say "The	conjunction was	'and' or ','\n")
		     )
$numd
( $numd ) -> Returns the length of the current direct object list. Equivalent to @Numd.
	Example:
		     (IF ($gt ($numd) 1) THEN
			     ($say "You	may not	use multiple direct objects!\n")
		     )

7.6. Transition Routines

ADL has an internal structure known as the Transition Vector. This structure is a list of ten verb IDs and is set and used by the following routines. These routines are typically used in the ACTION routines of rooms in scenarios in order to move the player around.

$setv
( $setv verb1 verb2 verb3 ... verb10 ) -> No return value. Initializes the Transition Vector to the list of verbs verb1 verb2 verb3 ... verb10.
	Example:
		     ($setv north south	east west ne se	nw sw up down)
$hit
( $hit obj loc1 loc2 loc3 ... loc10 ) -> No return value. Scans the Transition Vector for a match with the current Verb. If found, obj is moved to the corresponding loc. Nothing happens if no match is found. An attempt to move an object to location 0 (.ALL) is ignored.
	Example:
		     room1(ACTION) =
			     ($hit .ME room2 room3 room4 0 0 0 0 0 0 0)
		     ;
$miss
( $miss rout1 rout2 rout3 ... rout10 ) -> No return value. Scans the Transition Vector for a match with the current Verb. If found, the corresponding rout is called. Nothing happens if no match is found. An attempt to call routine 0 does nothing.
	Example:
		     cg	= ($say	"You can't go that way.\n")

		     room2(ACTION) =
			     ($miss 0 0	0 cg cg	cg cg cg cg cg)
		     ;

7.7. String Manipulation Routines

There are basically three types of strings which an ADL program uses. The first type of string is the compile-time string (a string which was present in the ADL source file of the scenario). All compile-time strings have a positive string ID and exist for the duration of program execution.

The second type of string is the "volatile" run-time string. Examples of this type of string include strings typed by the player and strings produced by the builtin routines $subs, $cat, $read, $name, $vname, $mname, $pname, $num, and $chr (see also Sections 7.8 and 7.9). Volatile strings have negative string IDs and are "flushed" at the beginning of each turn (just before the Daemon phase).

The third type of string is the "non-volatile" run-time string. These strings also have negative string IDs but they are never "flushed". These strings are produced by the $savestr routine. Note that there is no easy way to distinguish volatile and non-volatile run-time strings.

In the context of the $subs and $pos routines, strings are indexed starting at zero (the first character of the string). The following routines operate on all types of strings:

$eqst
( $eqst str1 str2 ) -> Returns one if str1 has the same contents as str2 and zero otherwise. Note that this is NOT the same as ($eq str1 str2), since the $eq only compares the string IDs of the strings.
	Example:
		     The program:
			     ($setg str1 "hello")
			     ($setg str2 ($cat "he" "llo"))
			     (IF ($eqst	@str1 @str2) THEN
				     ($say "String 1 ==	string 2\n")
			     )
			     (IF ($ne @str1 @str2) THEN
				     ($say "String ID 1	!= string ID 2\n")
			     )

		     will produce the output:
			     String 1 == string	2
			     String ID 1 != string ID 2
$subs
( $subs str start len ) -> Returns a volatile copy of the substring of str starting at start and going for len characters. If len is 0, the suffix of str starting at start is returned.
	Example:
		     The program:
			     ($setg str	"Hello world")
			     ($say ($subs @str 0 5) "\n")
			     ($say ($subs @str 6 0) "\n")

		     will produce the output:
			     Hello
			     world
$leng
( $leng str ) -> Returns the length of str.
	Example:
		     ($leng "Hello") is	5
		     ($leng "")	is 0
$cat
( $cat str1 str2 ) -> Returns a volatile string which is the result of concatenating str1 and str2.
	Example:
		     ($cat "hello " "world") returns "hello world"
$pos
( $pos str1 str2 ) -> Returns the position of str1 in str2. If no occurrence of str1 is found in str2, -1 is returned.
	Example:
		     ($pos "hello" "hello world") is 0
		     ($pos "Foobar" "bletch") is -1
		     ($pos "testing" "This is a	test") is -1
		     ($pos "is"	"This is a test") is 2
$read
( $read ) -> Returns a volatile string which is read from the player's keyboard. Note that no prompt is automatically generated.
	Example:
		     ($say "What is your name? ")
		     ($setg MyName ($read))
		     ($say "Hello, " @MyName ",	welcome	to ADL!\n")
$savestr( $savestr str )
-> Returns a non-volatile copy of str. Note that str may be any string -- compile- time, volatile, or non-volatile.
	Example:
		     ($setg MyName ($savestr @MyName))

7.8. Name Routines

The following routines all return volatile strings which contain the requested name.

$name
( $name obj ) -> Returns a volatile string contain- ing the (possibly multiple-word) name of obj.
	Example:
		     ($say "You	see no " ($name	@Dobj) " here!\n")
$vname
( $vname verb ) -> Returns a volatile string con- taining the name of verb.
	Example:
		     ($say "No multiple	objects	with " ($vname @Verb) "!\n")
$mname
( $mname modif ) -> Returns a volatile string con- taining: the name of modifier modif (if modif is greater than zero), the name of verb -modif (if modif is less than zero), or the null string (if modif is zero).
	Example:
		     ($say "The	modifier of blue ball is " ($mname blue) "\n")
$pname
( $pname prep ) -> Returns a volatile string con- taining the name of Preposition prep.
	Example:
		     ($say "The	sentence is:\n")
		     ($say   ($vname @Verb) " "
			     ($name @Dobj) " "
			     ($pname @Prep) " "
			     ($name @Iobj)
		     )

7.9. Conversion Routines

The following routines perform conversions between strings and numbers.

$str
( $str num ) -> Returns a volatile string which con- tains the ASCII representation of num.
	Example:
		     ($str 3) is the string "3"
$num
( $num str ) -> Returns the numeric value of str.
	Example:
		     ($num "234") is the number	234
$ord
( $ord str ) -> Returns the ASCII code of the first character in str.
	Example:
		     ($ord "ABC") is 65
$chr
( $chr num ) -> Returns a volatile string which con- tains exactly one character, whose ASCII code is num.
	Example:
		     ($chr 97) is the string "a".

7.10. Internal Structure Manipulation Routines

The following routines are the means whereby the ADL programmer may modify the Internal Structures described in Chapter 3. See also Chapter 4 for the use of some of these routines.

$sdem
( $sdem rout ) -> No return value. Activates rout as a daemon.
	Example:
		     ($sdem Looker)
		     ($sdem Follower)
$ddem
( $ddem rout ) -> No return value. De-activates rout as a daemon. No action is taken if rout is not an active daemon.
	Example:
		     ($ddem Follower)
$sfus
( $sfus actor rout count ) -> No return value. Activates rout as a fuse associated with actor to be executed in count turns.
	Example:
		     ($sfus .ME	LampDie	300)
$dfus
( $dfus actor rout ) -> No return value. De- activates rout as a fuse associated with actor. No action is taken if rout is not an active fuse.
	Example:
		     (IF @BatteryFound THEN
			     ($dfus .ME	LampDie)
		     )
$incturn( $incturn [ nturns ] )
-> No return value. Increments the turn counter by nturns (or 1 if nturns is not given) and activates any fuses associated with the current actor that have "burned down". The "burned down" fuses are then de-activated. The ADL programmer to "halt time" by refraining from incrementing the turn counter. Usually, ($incturn) is only called when the daemons are executing for the primary actor. For other actors, ($incturn 0) is used to see whether the fuses associated with the current actor have burned down, without incrementing the turn counter.
	Example:
		     sleep(ACTION) = ($incturn 300) ;
$turns
( $turns ) -> Returns the current value of the turn counter.
	Example:
		     (IF ($eq @Verb north) THEN
			     (IF ($gt ($turns) 230) THEN
				     ($move .ME	room3)
			      ELSE
				     ($move .ME	room5)
			     )
		     )
$prompt
( $prompt rout ) -> No return value. Sets the prompter to be rout.
	Example:
		     ($prompt Prompter)
$actor
( $actor obj str flag ) -> No return value. Activates obj as a new Actor with the line buffer initialized to str. If flag is non-zero then the new Actor will be interactive. If flag is zero then the new Actor will be non-interactive. If str is zero then the line buffer will be initialized to the empty string.
	Example:
		     ($actor Myself NULL TRUE)
		     ($setg s "Go east then south.  Push button.  Go north")
		     ($actor robot @s FALSE)
$delact
( $delact obj ) -> No return value. Deletes the Actor associated with obj from the Actor list. No action is performed if obj is not an active Actor.
	Example:
		     (IF ($prop	robot BROKEN) THEN
			     ($delact robot)
		     )
$define
( $define str1 str2 ) -> No return value. Informs the parser that upon input from an Actor, the string str1 is to be replaced with the contents of str2. This process continues until an infinite loop is detected or until a word is found for which there is no corresponding expansion. Str1 must contain no spaces. Str2 may contain several words separated by spaces. Note that in the case of multiple definitions (such as ($define "a" "b") followed by ($define "a" "c")), the macro table should be viewed as a stack with $define pushing macro definitions on the stack and $undef popping definitions.
	Example:
		     (IF ($eq @MyDir 1)	THEN
			     ($define "left" "north")
			     ($define "right" "south")
		      ELSE
			     ($define "left" "south")
			     ($define "right" "north")
		     )
$undef
( $undef str ) -> No return value. This routine removes str and its expansion from the macro table. No action is performed if str is not an active macro.
	Example:
		     ($undef "left")
		     ($undef "right")

7.11. Special Routines

$spec
( $spec code arg1 arg2 ... argN ) -> No return value. Performs a special, system-dependent operation. Note that not all operations exist in all implementations. Consult your local ADL documentation for information.
	  +------+---------------------------------------+
	  | code |		 function		 |
	  +------+---------------------------------------+
	  |  1	 |   Toggle the	instruction trace flag	 |
	  |  2	 |	     Restart this game		 |
	  |  3	 |    Terminate	execution of this game	 |
	  |  4	 |	Save this game in file arg1	 |
	  |  5	 |    Restore this game	from file arg1	 |
	  |  6	 | Execute the system program named arg1 |
	  |  7	 |  Preserve unknown words in file arg1	 |
	  |  8	 |	Write a	script to file arg1	 |
	  |  9	 |   Print a header line on the	screen	 |
	  |  10	 |	    Set	the right margin	 |
	  +------+---------------------------------------+
Function 1
Toggles the instruction trace flag. If this flag is set, an instruction trace and stack dump are printed for every ADL instruction executed (a very messy but informative process).
Function 2
Re-initializes all ADL structures and variables, re-executes START, and generally starts the game over from the beginning.
Function 3
Terminates the game immediately, no questions asked.
Function 4
Saves a "core image" of the ADL structures and variables sufficient to restore the game to the same position later.
Function 5
Reads a "core image" which was created by a previous invocation of Function 4, thus restoring the game to its previous state.
Function 6
Runs the program arg1 with arguments arg2 through argN. All arguments must be strings, except the last argument which must be 0.
Function 7
Starts recording those words from the player's input which are unrecognized by the run-time parser. The words are appended to the file named by arg1. This recording is stopped if arg1 is 0.
Function 8
Starts recording a "script" of all input and output produced during the subsequent execution of the game. The script is written into the file named by arg1. Stops recording if arg1 is 0.
Function 9
Prints a line of the form "Room Name Score: NN Moves: NN" at the top of the screen. It is assumed that arg1 is the name of the room, arg2 is the current score, and arg3 is the number of turns that have passed.
Function 10
Sets the right margin to arg1. This function is provided for the use of those games whose messages would look better on narrower (or wider) screens than the default of 80 columns.
	Examples:
		     VERB debug;
		     debug(ACTION) = ($spec 1);

		     VERB restart;
		     restart(ACTION) = ($spec 2);

		     VERB quit;
		     quit(ACTION) = ($spec 3);

		     VERB save;
		     save(ACTION) =
		     LOCAL name;
			     ($say "Save to what filename? ")
			     ($setg name ($read))
			     (IF ($leng	@name) THEN
				     ($spec 4 @name)
			     )
		     ;

		     VERB restore;
		     restore(ACTION) =
		     LOCAL name;
			     ($say "Restore from what filename?	")
			     ($setg name ($read))
			     (IF ($leng	@name) THEN
				     ($spec 5 @name)
			     )
		     ;

		     VERB shell;
		     shell(ACTION) =
			     ($spec 6 "/bin/csh")
		     ;

		     VERB savewords;
		     savewords(ACTION) =
			     ($spec 7 "unknown.wrds")
		     ;

		     VERB script;
		     script(ACTION) =
		     LOCAL name;
			     ($say "Script to what filename? ")
			     ($setg name ($read))
			     (IF ($leng	@name) THEN
				     ($spec 8 @name)
			     )
		     ;

		     Status = ($spec 9 ($name ($loc .ME)) @Score ($turns)) ;

		     START = ($spec 10 60);  { It makes	the text prettier }

7.12. Miscellaneous Routines

These routines are placed here for lack of a better place to put them.

$say
( $say str1 str2 ... ) -> No return value. Prints the messages str1 str2 ... on the screen. Note that ADL automatically "word-wraps" strings so that they fit within the right margin as closely as possible. Therefore, it is not necessary for the ADL programmer to take great care in formatting the messages passed to $say. If the programmer desires that the current line be terminated, and output start on a new line, the character sequence "\n" should be embedded in the string. Note that each str may actually be an expression such as ($name foo) or ($num @Score).
	Example:
		     ($say "Hi!	 My name is " @MyName "! How are you today?\n")
		     Note that MyName is assumed to contain a string ID.
$arg
( $arg num ) -> Returns the numth argument of the current routine. It is basically the same as %num except that in this case num may be a numeric expression, not just a numeric constant. ($arg 0) returns the number of arguments passed to this invo- cation of the current routine.
	Example:
		     { Print all of the	arguments to this routine }
		     ($setg i 1)
		     (WHILE ($le @i %0)	DO
			     ($say "Arg	" @i " = " ($arg @i) "\n")
		     )
$exit
( $exit code ) -> Doesn't return to the current routine. $exit terminates execution of the current phase. If code is 0, control passes to the next phase. If code is 1, control passes to the outer- most loop. If code is 2, control passes to the top of the Dobj loop. If code is 3, control passes to the parser which attempts to complete a partial sentence. See the diagram in Chapter 4 for a complete definition.
	Example:
		     take(PREACT) =
			     (IF ($ne ($loc @Dobj) ($loc .ME)) THEN
				     ($say "You	don't see that here!\n")
				     { Skip the	rest of	the phases }
				     ($exit 1)
			     )
		     ;
		     safe(ACTION) =
			     (IF ($eq @Verb take) THEN
				     ($say "You	can't budge the	safe.\n")
				     { Go on to	the rest of the	Dobjs }
				     ($exit 2)
			     )
		     ;
		     ball(ACTION) =
			     (IF ($prop	ball BROKEN) THEN
				     { Rely on the default verb	ACTION }
				     ($exit 0)
			     )
			     ($say "The	ball bounces nicely.\n")
		     ;
		     NOVERB(PREACT) =
			     ($say "What do you	want me	to do with the "
			     ($say ($name @Dobj) "?\n")
			     { Re-parse	the sentence }
			     ($exit 3)
		     ;
$return
( $return expr ) -> Doesn't return to the current routine. Evaluates expr and returns the result to the current routine's caller. Note that in the absence of an explicit $return, the return value of a routine is the same as the value of the last statement executed.
	Example:
		     Increment = ($return ($plus %1 1))

		     ($say "Increment( 3 ) = " (Increment 3) "\n")
			     Increment(	3 ) = 4
$val
( $val expr ) -> Evaluates expr and returns the result. Expr may be a routine call, a constant, a string, or anything that yields a 16-bit value. This routine is most useful in conditional expressions.
	Example:
		     Signum =
			     (IF ($lt %1 0) THEN
				     ($val -1)
			      ELSEIF ($eq %1 0)	THEN
				     ($val 0)
			      ELSE
				     ($val 1)
			     )
		     ;
$phase
( $phase ) -> Returns the number of the phase currently executing. This number is 0 during the START phase, 1 during the Daemon phase, 2 during the Actor ACTION, 3 during the Verb PREACT, 4 during the Iobj ACTION, 5 during the Dobj ACTION, 6 during the Verb ACTION, and 7 during the Room ACTION.
	Example:
			     (IF ($eq ($phase) 2) THEN
				     ($say "This is the	Actor ACTION\n")
			      ELSEIF ($eq ($phase) 4) THEN
				     ($say "This is the	Iobj ACTION\n")
			      ELSEIF ($eq ($phase) 5) THEN
				     ($say "This is the	Dobj ACTION\n")
			     )