Contents | Index | < Browse | Browse >

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  expres-
sion 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  expres-
	      sion  ...	 ).   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)
		   ;