<HTML>
<HEAD>
<!-- This HTML file has been created by texi2html 1.46
     from ProgrammersManual.texinfo on 20 January 1997 -->

<TITLE>LambdaMOO Programmer's Manual</TITLE>
</HEAD>
<BODY>
<H1>LambdaMOO Programmer's Manual</H1>


<H1><A NAME="SEC1" HREF="ProgrammersManual_toc.html#SEC1">Introduction</A></H1>

<P>
LambdaMOO is a network-accessible, multi-user, programmable, interactive
system well-suited to the construction of text-based adventure games,
conferencing systems, and other collaborative software.  Its most common use,
however, is as a multi-participant, low-bandwidth virtual reality, and it is
with this focus in mind that I describe it here.

</P>
<P>
Participants (usually referred to as <STRONG>players</STRONG>) connect to LambdaMOO using
Telnet or some other, more specialized, <STRONG>client</STRONG> program.  Upon
connection, they are usually presented with a <STRONG>welcome message</STRONG> explaining
how to either create a new <STRONG>character</STRONG> or connect to an existing one.
Characters are the embodiment of players in the virtual reality that is
LambdaMOO.

</P>
<P>
Having connected to a character, players then give one-line commands that are
parsed and interpreted by LambdaMOO as appropriate.  Such commands may cause
changes in the virtual reality, such as the location of a character, or may
simply report on the current state of that reality, such as the appearance of
some object.

</P>
<P>
The job of interpreting those commands is shared between the two major
components in the LambdaMOO system: the <STRONG>server</STRONG> and the <STRONG>database</STRONG>.
The server is a program, written in a standard programming language, that
manages the network connections, maintains queues of commands and other tasks
to be executed, controls all access to the database, and executes other
programs written in the MOO programming language.  The database contains
representations of all the objects in the virtual reality, including the MOO
programs that the server executes to give those objects their specific
behaviors.

</P>
<P>
Almost every command is parsed by the server into a call on a MOO procedure,
or <STRONG>verb</STRONG>, that actually does the work.  Thus, programming in the MOO
language is a central part of making non-trivial extensions to the database
and thus, the virtual reality.

</P>
<P>
In the next chapter, I describe the structure and contents of a LambdaMOO
database.  The following chapter gives a complete description of how the
server performs its primary duty: parsing the commands typed by players.
Next, I describe the complete syntax and semantics of the MOO programming
language.  Finally, I describe all of the database conventions assumed by the
server.

</P>

<BLOCKQUOTE>
<P>
<STRONG>Note:</STRONG> This manual describes only those aspects of LambdaMOO that are
entirely independent of the contents of the database.  It does not describe,
for example, the commands or programming interfaces present in the LambdaCore
database.
</BLOCKQUOTE>



<H1><A NAME="SEC2" HREF="ProgrammersManual_toc.html#SEC2">The LambdaMOO Database</A></H1>

<P>
In this chapter, I begin by describing in detail the various kinds of data
that can appear in a LambdaMOO database and that, therefore, MOO programs can
manipulate.  In a few places, I refer to the <STRONG>LambdaCore</STRONG> database.  This
is one particular LambdaMOO database, created every so often by extracting the
"core" of the current database for the original LambdaMOO.

</P>

<BLOCKQUOTE>
<P>
<STRONG>Note</STRONG>: The original LambdaMOO resides on the host
<CODE>lambda.parc.xerox.com</CODE> (the numeric address for which is
<CODE>192.216.54.2</CODE>), on port 8888.  Feel free to drop by!  A copy of the most
recent release of the LambdaCore database can be obtained by anonymous FTP from
host <CODE>ftp.parc.xerox.com</CODE> in the directory <CODE>pub/MOO</CODE>.
</BLOCKQUOTE>



<H2><A NAME="SEC3" HREF="ProgrammersManual_toc.html#SEC3">MOO Value Types</A></H2>

<P>
There are only a few kinds of values that MOO programs can manipulate:

</P>

<UL>
<LI>

integers (in a specific, large range)
<LI>

real numbers (represented with floating-point numbers)
<LI>

strings (of characters)
<LI>

objects (in the virtual reality)
<LI>

errors (arising during program execution)
<LI>

lists (of all of the above, including lists)
</UL>

<P>
MOO supports the integers from -2^31 (that is, negative two to the power
of 31) up to 2^31 - 1 (one less than two to the power of 31); that's
from -2147483648 to 2147483647, enough for most purposes.  In MOO
programs, integers are written just as you see them here, an optional minus
sign followed by a non-empty sequence of decimal digits.  In particular, you
may not put commas, periods, or spaces in the middle of large integers, as we
sometimes do in English and other natural languages (e.g., `2,147,483,647').

</P>
<P>
Real numbers in MOO are represented as they are in almost all other programming
languages, using so-called <STRONG>floating-point</STRONG> numbers.  These have certain
(large) limits on size and precision that make them useful for a wide range of
applications.  Floating-point numbers are written with an optional minus sign
followed by a non-empty sequence of digits punctuated at some point with a
decimal point (`.') and/or followed by a scientific-notation marker (the letter
`E' or `e' followed by an optional sign and one or more digits).  Here are some
examples of floating-point numbers:

</P>

<PRE>
325.0   325.   3.25e2   0.325E3   325.E1   .0325e+4   32500e-2
</PRE>

<P>
All of these examples mean the same number.  The third of these, as an example
of scientific notation, should be read "3.25 times 10 to the power of 2".

</P>

<BLOCKQUOTE>
<P>
<EM>Fine points:</EM> The MOO represents floating-point numbers using the local
meaning of the C-language <CODE>double</CODE> type, which is almost always equivalent
to IEEE 754 double precision floating point.  If so, then the smallest positive
floating-point number is no larger than <CODE>2.2250738585072014e-308</CODE> and the
largest floating-point number is <CODE>1.7976931348623157e+308</CODE>.

</P>
<P>
IEEE infinities and NaN values are not allowed in MOO.  The error
<CODE>E_FLOAT</CODE> is raised whenever an infinity would otherwise be computed;
<CODE>E_INVARG</CODE> is raised whenever a NaN would otherwise arise.  The value
<CODE>0.0</CODE> is always returned on underflow.
</BLOCKQUOTE>

<P>
Character <STRONG>strings</STRONG> are arbitrarily-long sequences of normal, ASCII
printing characters.  When written as values in a program, strings are
enclosed in double-quotes, like this:

</P>

<PRE>
"This is a character string."
</PRE>

<P>
To include a double-quote in the string, precede it with a backslash
(<SAMP>`\'</SAMP>), like this:

</P>

<PRE>
"His name was \"Leroy\", but nobody ever called him that."
</PRE>

<P>
Finally, to include a backslash in a string, double it:

</P>

<PRE>
"Some people use backslash ('\\') to mean set difference."
</PRE>

<P>
MOO strings may not include special ASCII characters like carriage-return,
line-feed, bell, etc.  The only non-printing characters allowed are spaces and
tabs.

</P>

<BLOCKQUOTE>
<P>
<EM>Fine point:</EM> There is a special kind of string used for representing the
arbitrary bytes used in general, binary input and output.  In a <STRONG>binary
string</STRONG>, any byte that isn't an ASCII printing character or the space character
is represented as the three-character substring "~XX", where XX is the
hexadecimal representation of the byte; the input character `~' is represented
by the three-character substring "~7E".  This special representation is used by
the functions <CODE>encode_binary()</CODE> and <CODE>decode_binary()</CODE> and by the
functions <CODE>notify()</CODE> and <CODE>read()</CODE> with network connections that are
in binary mode.  See the descriptions of the <CODE>set_connection_option()</CODE>,
<CODE>encode_binary()</CODE>, and <CODE>decode_binary()</CODE> functions for more details.
</BLOCKQUOTE>

<P>
<STRONG>Objects</STRONG> are the backbone of the MOO database and, as such, deserve a
great deal of discussion; the entire next section is devoted to them.  For now,
let it suffice to say that every object has a number, unique to that object.
In programs, we write a reference to a particular object by putting a hash mark
(<SAMP>`#'</SAMP>) followed by the number, like this:

</P>

<PRE>
#495
</PRE>

<P>
Object numbers are always integers.

</P>
<P>
There are three special object numbers used for a variety of purposes:
<CODE>#-1</CODE>, <CODE>#-2</CODE>, and <CODE>#-3</CODE>, usually referred to in the
LambdaCore database as <CODE>$nothing</CODE>, <CODE>$ambiguous_match</CODE>, and
<CODE>$failed_match</CODE>, respectively.

</P>
<P>
<STRONG>Errors</STRONG> are, by far, the least frequently used values in MOO.  In the
normal case, when a program attempts an operation that is erroneous for some
reason (for example, trying to add a number to a character string), the server
stops running the program and prints out an error message.  However, it is
possible for a program to stipulate that such errors should not stop execution;
instead, the server should just let the value of the operation be an error
value.  The program can then test for such a result and take some appropriate
kind of recovery action.  In programs, error values are written as words
beginning with <SAMP>`E_'</SAMP>.  The complete list of error values, along with their
associated messages, is as follows:

</P>

<PRE>
E_NONE      No error
E_TYPE      Type mismatch
E_DIV       Division by zero
E_PERM      Permission denied
E_PROPNF    Property not found
E_VERBNF    Verb not found
E_VARNF     Variable not found
E_INVIND    Invalid indirection
E_RECMOVE   Recursive move
E_MAXREC    Too many verb calls
E_RANGE     Range error
E_ARGS      Incorrect number of arguments
E_NACC      Move refused by destination
E_INVARG    Invalid argument
E_QUOTA     Resource limit exceeded
E_FLOAT     Floating-point arithmetic error
</PRE>

<P>
The final kind of value in MOO programs is <STRONG>lists</STRONG>.  A list is a sequence
of arbitrary MOO values, possibly including other lists.  In programs,
lists are written in mathematical set notation with each of the elements
written out in order, separated by commas, the whole enclosed in curly
braces (<SAMP>`{'</SAMP> and <SAMP>`}'</SAMP>).  For example, a list of the names of
the days of the week is written like this:

</P>

<PRE>
{"Sunday", "Monday", "Tuesday", "Wednesday",
 "Thursday", "Friday", "Saturday"}
</PRE>

<P>
Note that it doesn't matter that we put a line-break in the middle of
the list.  This is true in general in MOO: anywhere that a space can go,
a line-break can go, with the same meaning.  The only exception is
inside character strings, where line-breaks are not allowed.

</P>


<H2><A NAME="SEC4" HREF="ProgrammersManual_toc.html#SEC4">Objects in the MOO Database</A></H2>

<P>
Objects are, in a sense, the whole point of the MOO programming language.
They are used to represent objects in the virtual reality, like people, rooms,
exits, and other concrete things.  Because of this, MOO makes a bigger deal
out of creating objects than it does for other kinds of value, like integers.

</P>
<P>
Numbers always exist, in a sense; you have only to write them down in order to
operate on them.  With objects, it is different.  The object with number
<SAMP>`#958'</SAMP> does not exist just because you write down its number.  An
explicit operation, the <SAMP>`create()'</SAMP> function described later, is required
to bring an object into existence.  Symmetrically, once created, objects
continue to exist until they are explicitly destroyed by the <SAMP>`recycle()'</SAMP>
function (also described later).

</P>
<P>
The identifying number associated with an object is unique to that
object.  It was assigned when the object was created and will never be
reused, even if the object is destroyed.  Thus, if we create an object
and it is assigned the number <SAMP>`#1076'</SAMP>, the next object to be
created will be assigned <SAMP>`#1077'</SAMP>, even if <SAMP>`#1076'</SAMP> is destroyed
in the meantime.

</P>
<P>
Every object is made up of three kinds of pieces that together define its
behavior: <STRONG>attributes</STRONG>, <STRONG>properties</STRONG>, and <STRONG>verbs</STRONG>.

</P>



<H3><A NAME="SEC5" HREF="ProgrammersManual_toc.html#SEC5">Fundamental Object Attributes</A></H3>

<P>
There are three fundamental <STRONG>attributes</STRONG> to every object:

</P>

<OL>
<LI>

A flag (either true or false) specifying whether or not the object represents
a player,
<LI>

The object that is its <STRONG>parent</STRONG>, and
<LI>

A list of the objects that are its <STRONG>children</STRONG>; that is, those objects for
which this object is their parent.
</OL>

<P>
The act of creating a character sets the player attribute of an object and
only a wizard (using the function <CODE>set_player_flag()</CODE>) can change that
setting.  Only characters have the player bit set to 1.

</P>
<P>
The parent/child hierarchy is used for classifying objects into general classes
and then sharing behavior among all members of that class.  For example, the
LambdaCore database contains an object representing a sort of "generic" room.
All other rooms are <STRONG>descendants</STRONG> (i.e., children or children's children,
or ...) of that one.  The generic room defines those pieces of behavior
that are common to all rooms; other rooms specialize that behavior for their
own purposes.  The notion of classes and specialization is the very essence of
what is meant by <STRONG>object-oriented</STRONG> programming.  Only the functions
<CODE>create()</CODE>, <CODE>recycle()</CODE>, <CODE>chparent()</CODE>, and <CODE>renumber()</CODE> can
change the parent and children attributes.

</P>


<H3><A NAME="SEC6" HREF="ProgrammersManual_toc.html#SEC6">Properties on Objects</A></H3>

<P>
A <STRONG>property</STRONG> is a named "slot" in an object that can hold an arbitrary
MOO value.  Every object has eight built-in properties whose values are
constrained to be of particular types.  In addition, an object can have any
number of other properties, none of which have type constraints.  The built-in
properties are as follows:

</P>

<PRE>
name         a string, the usual name for this object
owner        an object, the player who controls access to it
location     an object, where the object is in virtual reality
contents     a list of objects, the inverse of <SAMP>`location'</SAMP>
programmer   a bit, does the object have programmer rights?
wizard       a bit, does the object have wizard rights?
r            a bit, is the object publicly readable?
w            a bit, is the object publicly writable?
f            a bit, is the object fertile?
</PRE>

<P>
The <SAMP>`name'</SAMP> property is used to identify the object in various printed
messages.  It can only be set by a wizard or by the owner of the object.  For
player objects, the <SAMP>`name'</SAMP> property can only be set by a wizard; this
allows the wizards, for example, to check that no two players have the same
name.

</P>
<P>
The <SAMP>`owner'</SAMP> identifies the object that has owner rights to this object,
allowing them, for example, to change the <SAMP>`name'</SAMP> property.  Only a wizard
can change the value of this property.

</P>
<P>
The <SAMP>`location'</SAMP> and <SAMP>`contents'</SAMP> properties describe a hierarchy of
object containment in the virtual reality.  Most objects are located
"inside" some other object and that other object is the value of the
<SAMP>`location'</SAMP> property.  The <SAMP>`contents'</SAMP> property is a list of those
objects for which this object is their location.  In order to maintain the
consistency of these properties, only the <CODE>move()</CODE> function is able to
change them.

</P>
<P>
The <SAMP>`wizard'</SAMP> and <SAMP>`programmer'</SAMP> bits are only applicable to
characters, objects representing players.  They control permission to use
certain facilities in the server.  They may only be set by a wizard.

</P>
<P>
The <SAMP>`r'</SAMP> bit controls whether or not players other than the owner of this
object can obtain a list of the properties or verbs in the object.
Symmetrically, the <SAMP>`w'</SAMP> bit controls whether or not non-owners can add or
delete properties and/or verbs on this object.  The <SAMP>`r'</SAMP> and <SAMP>`w'</SAMP> bits
can only be set by a wizard or by the owner of the object.

</P>
<P>
The <SAMP>`f'</SAMP> bit specifies whether or not this object is <STRONG>fertile</STRONG>, whether
or not players other than the owner of this object can create new objects with
this one as the parent.  It also controls whether or not non-owners can use the
<CODE>chparent()</CODE> built-in function to make this object the parent of an
existing object.  The <SAMP>`f'</SAMP> bit can only be set by a wizard or by the owner
of the object.

</P>
<P>
All of the built-in properties on any object can, by default, be read by any
player.  It is possible, however, to override this behavior from within the
database, making any of these properties readable only by wizards.  See the
chapter on server assumptions about the database for details.

</P>
<P>
As mentioned above, it is possible, and very useful, for objects to have other
properties aside from the built-in ones.  These can come from two sources.

</P>
<P>
First, an object has a property corresponding to every property in its parent
object.  To use the jargon of object-oriented programming, this is a kind of
<STRONG>inheritance</STRONG>.  If some object has a property named <SAMP>`foo'</SAMP>, then so
will all of its children and thus its children's children, and so on.

</P>
<P>
Second, an object may have a new property defined only on itself and its
descendants.  For example, an object representing a rock might have properties
indicating its weight, chemical composition, and/or pointiness, depending upon
the uses to which the rock was to be put in the virtual reality.

</P>
<P>
Every defined property (as opposed to those that are built-in) has an owner
and a set of permissions for non-owners.  The owner of the property can get
and set the property's value and can change the non-owner permissions.  Only a
wizard can change the owner of a property.

</P>
<P>
The initial owner of a property is the player who added it; this is usually,
but not always, the player who owns the object to which the property was
added.  This is because properties can only be added by the object owner or a
wizard, unless the object is publicly writable (i.e., its <SAMP>`w'</SAMP> property is
1), which is rare.  Thus, the owner of an object may not necessarily be the
owner of every (or even any) property on that object.

</P>
<P>
The permissions on properties are drawn from this set: <SAMP>`r'</SAMP> (read),
<SAMP>`w'</SAMP> (write), and <SAMP>`c'</SAMP> (change ownership in descendants).  Read
permission lets non-owners get the value of the property and, of course, write
permission lets them set that value.  The <SAMP>`c'</SAMP> permission bit is a little
more complicated.

</P>
<P>
Recall that every object has all of the properties that its parent does and
perhaps some more.  Ordinarily, when a child object inherits a property from
its parent, the owner of the child becomes the owner of that property.  This
is because the <SAMP>`c'</SAMP> permission bit is "on" by default.  If the <SAMP>`c'</SAMP>
bit is not on, then the inherited property has the same owner in the child as
it does in the parent.

</P>
<P>
As an example of where this can be useful, the LambdaCore database ensures
that every player has a <SAMP>`password'</SAMP> property containing the encrypted
version of the player's connection password.  For security reasons, we don't
want other players to be able to see even the encrypted version of the
password, so we turn off the <SAMP>`r'</SAMP> permission bit.  To ensure that the
password is only set in a consistent way (i.e., to the encrypted version of a
player's password), we don't want to let anyone but a wizard change the
property.  Thus, in the parent object for all players, we made a wizard the
owner of the password property and set the permissions to the empty string,
<CODE>""</CODE>.  That is, non-owners cannot read or write the property and, because
the <SAMP>`c'</SAMP> bit is not set, the wizard who owns the property on the parent
class also owns it on all of the descendants of that class.

</P>
<P>
Another, perhaps more down-to-earth example arose when a character named Ford
started building objects he called "radios" and another character, yduJ,
wanted to own one.  Ford kindly made the generic radio object fertile, allowing
yduJ to create a child object of it, her own radio.  Radios had a property
called <SAMP>`channel'</SAMP> that identified something corresponding to the frequency
to which the radio was tuned.  Ford had written nice programs on radios (verbs,
discussed below) for turning the channel selector on the front of the radio,
which would make a corresponding change in the value of the <SAMP>`channel'</SAMP>
property.  However, whenever anyone tried to turn the channel selector on
yduJ's radio, they got a permissions error.  The problem concerned the
ownership of the <SAMP>`channel'</SAMP> property.

</P>
<P>
As I explain later, programs run with the permissions of their author.  So, in
this case, Ford's nice verb for setting the channel ran with his permissions.
But, since the <SAMP>`channel'</SAMP> property in the generic radio had the <SAMP>`c'</SAMP>
permission bit set, the <SAMP>`channel'</SAMP> property on yduJ's radio was owned by
her.  Ford didn't have permission to change it!  The fix was simple.  Ford
changed the permissions on the <SAMP>`channel'</SAMP> property of the generic radio to
be just <SAMP>`r'</SAMP>, without the <SAMP>`c'</SAMP> bit, and yduJ made a new radio.  This
time, when yduJ's radio inherited the <SAMP>`channel'</SAMP> property, yduJ did not
inherit ownership of it; Ford remained the owner.  Now the radio worked
properly, because Ford's verb had permission to change the channel.

</P>


<H3><A NAME="SEC7" HREF="ProgrammersManual_toc.html#SEC7">Verbs on Objects</A></H3>

<P>
The final kind of piece making up an object is <STRONG>verbs</STRONG>.  A verb is a named
MOO program that is associated with a particular object.  Most verbs implement
commands that a player might type; for example, in the LambdaCore database,
there is a verb on all objects representing containers that implements
commands of the form `put <VAR>object</VAR> in <VAR>container</VAR>'.  It is also
possible for MOO programs to invoke the verbs defined on objects.  Some verbs,
in fact, are designed to be used only from inside MOO code; they do not
correspond to any particular player command at all.  Thus, verbs in MOO are
like the `procedures' or `methods' found in some other programming languages.

</P>
<P>
As with properties, every verb has an owner and a set of permission bits.  The
owner of a verb can change its program, its permission bits, and its argument
specifiers (discussed below).  Only a wizard can change the owner of a verb.
The owner of a verb also determines the permissions with which that verb runs;
that is, the program in a verb can do whatever operations the owner of that
verb is allowed to do and no others.  Thus, for example, a verb owned by a
wizard must be written very carefully, since wizards are allowed to do just
about anything.

</P>
<P>
The permission bits on verbs are drawn from this set: <SAMP>`r'</SAMP> (read),
<SAMP>`w'</SAMP> (write), <SAMP>`x'</SAMP> (execute), and <SAMP>`d'</SAMP> (debug).  Read permission
lets non-owners see the program for a verb and, symmetrically, write
permission lets them change that program.  The other two bits are not,
properly speaking, permission bits at all; they have a universal effect,
covering both the owner and non-owners.

</P>
<P>
The execute bit determines whether or not the verb can be invoked from within
a MOO program (as opposed to from the command line, like the <SAMP>`put'</SAMP> verb
on containers).  If the <SAMP>`x'</SAMP> bit is not set, the verb cannot be called
from inside a program.  The <SAMP>`x'</SAMP> bit is usually set.

</P>
<P>
The setting of the debug bit determines what happens when the verb's program
does something erroneous, like subtracting a number from a character string.
If the <SAMP>`d'</SAMP> bit is set, then the server <STRONG>raises</STRONG> an error value; such
raised errors can be <STRONG>caught</STRONG> by certain other pieces of MOO code.  If the
error is not caught, however, the server aborts execution of the command and,
by default, prints an error message on the terminal of the player whose command
is being executed.  (See the chapter on server assumptions about the database
for details on how uncaught errors are handled.)  If the <SAMP>`d'</SAMP> bit is not
set, then no error is raised, no message is printed, and the command is not
aborted; instead the error value is returned as the result of the erroneous
operation.

</P>

<BLOCKQUOTE>
<P>
<STRONG>Note:</STRONG> the <SAMP>`d'</SAMP> bit exists only for historical reasons; it used to
be the only way for MOO code to catch and handle errors.  With the introduction
of the <CODE>try</CODE>-<CODE>except</CODE> statement and the error-catching expression,
the <SAMP>`d'</SAMP> bit is no longer useful.  All new verbs should have the <SAMP>`d'</SAMP>
bit set, using the newer facilities for error handling if desired.  Over time,
old verbs written assuming the <SAMP>`d'</SAMP> bit would not be set should be changed
to use the new facilities instead.
</BLOCKQUOTE>

<P>
In addition to an owner and some permission bits, every verb has three
`argument specifiers', one each for the direct object, the preposition, and
the indirect object.  The direct and indirect specifiers are each drawn from
this set: <SAMP>`this'</SAMP>, <SAMP>`any'</SAMP>, or <SAMP>`none'</SAMP>.  The preposition specifier
is <SAMP>`none'</SAMP>, <SAMP>`any'</SAMP>, or one of the items in this list:

</P>

<PRE>
with/using
at/to
in front of
in/inside/into
on top of/on/onto/upon
out of/from inside/from
over
through
under/underneath/beneath
behind
beside
for/about
is
as
off/off of
</PRE>

<P>
The argument specifiers are used in the process of parsing commands,
described in the next chapter.

</P>


<H1><A NAME="SEC8" HREF="ProgrammersManual_toc.html#SEC8">The Built-in Command Parser</A></H1>

<P>
The MOO server is able to do a small amount of parsing on the commands
that a player enters.  In particular, it can break apart commands that
follow one of the following forms:

</P>

<PRE>
<VAR>verb</VAR>
<VAR>verb</VAR> <VAR>direct-object</VAR>
<VAR>verb</VAR> <VAR>direct-object</VAR> <VAR>preposition</VAR> <VAR>indirect-object</VAR>
</PRE>

<P>
Real examples of these forms, meaningful in the LambdaCore database, are
as follows:

</P>

<PRE>
look
take yellow bird
put yellow bird in cuckoo clock
</PRE>

<P>
Note that English articles (i.e., <SAMP>`the'</SAMP>, <SAMP>`a'</SAMP>, and <SAMP>`an'</SAMP>) are not
generally used in MOO commands; the parser does not know that they are
not important parts of objects' names.

</P>
<P>
To have any of this make real sense, it is important to understand
precisely how the server decides what to do when a player types a
command.

</P>
<P>
First, the server checks whether or not the first non-blank character in the
command is one of the following:

</P>

<PRE>
"        :        ;
</PRE>

<P>
If so, that character is replaced by the corresponding command below, followed
by a space:

</P>

<PRE>
say      emote    eval
</PRE>

<P>
For example, the command

</P>

<PRE>
"Hi, there.
</PRE>

<P>
is treated exactly as if it were as follows:

</P>

<PRE>
say Hi, there.
</PRE>

<P>
The server next breaks up the command into words.  In the simplest case,
the command is broken into words at every run of space characters; for example,
the command <SAMP>`foo bar baz'</SAMP> would be broken into the words <SAMP>`foo'</SAMP>,
<SAMP>`bar'</SAMP>, and <SAMP>`baz'</SAMP>.  To force the server to include spaces in a
"word", all or part of a word can be enclosed in double-quotes.  For example,
the command

</P>

<PRE>
foo "bar mumble" baz" "fr"otz" bl"o"rt
</PRE>

<P>
is broken into the words <SAMP>`foo'</SAMP>, <SAMP>`bar mumble'</SAMP>, <SAMP>`baz frotz'</SAMP>, and
<SAMP>`blort'</SAMP>.  Finally, to include a double-quote or a backslash in a word,
they can be preceded by a backslash, just like in MOO strings.

</P>
<P>
Having thus broken the string into words, the server next checks to see if the
first word names any of the six "built-in" commands: <SAMP>`.program'</SAMP>,
<SAMP>`PREFIX'</SAMP>, <SAMP>`OUTPUTPREFIX'</SAMP>, <SAMP>`SUFFIX'</SAMP>, <SAMP>`OUTPUTSUFFIX'</SAMP>, or the
connection's defined <STRONG>flush</STRONG> command, if any (<SAMP>`.flush'</SAMP> by default).
The first one of these is only available to programmers, the next four are
intended for use by client programs, and the last can vary from database to
database or even connection to connection; all six are described in the final
chapter of this document, "Server Commands and Database Assumptions".  If the
first word isn't one of the above, then we get to the usual case: a normal MOO
command.

</P>
<P>
The server next gives code in the database a chance to handle the command.  If
the verb <CODE>$do_command()</CODE> exists, it is called with the words of the
command passed as its arguments and <CODE>argstr</CODE> set to the raw command typed
by the user.  If <CODE>$do_command()</CODE> does not exist, or if that verb-call
completes normally (i.e., without suspending or aborting) and returns a false
value, then the built-in command parser is invoked to handle the command as
described below.  Otherwise, it is assumed that the database code handled the
command completely and no further action is taken by the server for that
command.

</P>
<P>
If the built-in command parser is invoked, the server tries to parse the
command into a verb, direct object, preposition and indirect object.  The first
word is taken to be the verb.  The server then tries to find one of the
prepositional phrases listed at the end of the previous section, using the
match that occurs earliest in the command.  For example, in the very odd
command <SAMP>`foo as bar to baz'</SAMP>, the server would take <SAMP>`as'</SAMP> as the
preposition, not <SAMP>`to'</SAMP>.

</P>
<P>
If the server succeeds in finding a preposition, it considers the words
between the verb and the preposition to be the direct object and those
after the preposition to be the indirect object.  In both cases, the
sequence of words is turned into a string by putting one space between
each pair of words.  Thus, in the odd command from the previous
paragraph, there are no words in the direct object (i.e., it is
considered to be the empty string, <CODE>""</CODE>) and the indirect object is
<CODE>"bar to baz"</CODE>.

</P>
<P>
If there was no preposition, then the direct object is taken to be all
of the words after the verb and the indirect object is the empty string.

</P>
<P>
The next step is to try to find MOO objects that are named by the direct
and indirect object strings.

</P>
<P>
First, if an object string is empty, then the corresponding object is the
special object <CODE>#-1</CODE> (aka <CODE>$nothing</CODE> in LambdaCore).  If an object
string has the form of an object number (i.e., a hash mark (<SAMP>`#'</SAMP>) followed
by digits), and the object with that number exists, then that is the named
object.  If the object string is either <CODE>"me"</CODE> or <CODE>"here"</CODE>, then the
player object itself or its location is used, respectively.

</P>
<P>
Otherwise, the server considers all of the objects whose location is either
the player (i.e., the objects the player is "holding", so to speak) or the
room the player is in (i.e., the objects in the same room as the player); it
will try to match the object string against the various names for these
objects.

</P>
<P>
The matching done by the server uses the <SAMP>`aliases'</SAMP> property of each of the
objects it considers.  The value of this property should be a list of strings,
the various alternatives for naming the object.  If it is not a list, or the
object does not have an <SAMP>`aliases'</SAMP> property, then the empty list is used.
In any case, the value of the <SAMP>`name'</SAMP> property is added to the list for the
purposes of matching.

</P>
<P>
The server checks to see if the object string in the command is either exactly
equal to or a prefix of any alias; if there are any exact matches, the prefix
matches are ignored.  If exactly one of the objects being considered has a
matching alias, that object is used.  If more than one has a match, then the
special object <CODE>#-2</CODE> (aka <CODE>$ambiguous_match</CODE> in LambdaCore) is used.
If there are no matches, then the special object <CODE>#-3</CODE> (aka
<CODE>$failed_match</CODE> in LambdaCore) is used.

</P>
<P>
So, now the server has identified a verb string, a preposition string,
and direct- and indirect-object strings and objects.  It then looks at
each of the verbs defined on each of the following four objects, in
order:

</P>

<OL>
<LI>

the player who typed the command,
<LI>

the room the player is in,
<LI>

the direct object, if any, and
<LI>

the indirect object, if any.
</OL>

<P>
For each of these verbs in turn, it tests if all of the the following
are true:

</P>

<UL>
<LI>

the verb string in the command matches one of the names for the
verb,
<LI>

the direct- and indirect-object values found by matching are allowed by
the corresponding argument specifiers for the verb, and
<LI>

the preposition string in the command is matched by the preposition
specifier for the verb.
</UL>

<P>
I'll explain each of these criteria in turn.

</P>
<P>
Every verb has one or more names; all of the names are kept in a single
string, separated by spaces.  In the simplest case, a verb-name is just
a word made up of any characters other than spaces and stars (i.e., ` '
and <SAMP>`*'</SAMP>).  In this case, the verb-name matches only itself; that
is, the name must be matched exactly.

</P>
<P>
If the name contains a single star, however, then the name matches any prefix
of itself that is at least as long as the part before the star.  For example,
the verb-name <SAMP>`foo*bar'</SAMP> matches any of the strings <SAMP>`foo'</SAMP>,
<SAMP>`foob'</SAMP>, <SAMP>`fooba'</SAMP>, or <SAMP>`foobar'</SAMP>; note that the star itself is not
considered part of the name.

</P>
<P>
If the verb name <EM>ends</EM> in a star, then it matches any string that begins
with the part before the star.  For example, the verb-name <SAMP>`foo*'</SAMP> matches
any of the strings <SAMP>`foo'</SAMP>, <SAMP>`foobar'</SAMP>, <SAMP>`food'</SAMP>, or <SAMP>`foogleman'</SAMP>,
among many others.  As a special case, if the verb-name is <SAMP>`*'</SAMP> (i.e., a
single star all by itself), then it matches anything at all.

</P>
<P>
Recall that the argument specifiers for the direct and indirect objects are
drawn from the set <SAMP>`none'</SAMP>, <SAMP>`any'</SAMP>, and <SAMP>`this'</SAMP>.  If the specifier
is <SAMP>`none'</SAMP>, then the corresponding object value must be <CODE>#-1</CODE> (aka
<CODE>$nothing</CODE> in LambdaCore); that is, it must not have been specified.  If
the specifier is <SAMP>`any'</SAMP>, then the corresponding object value may be
anything at all.  Finally, if the specifier is <SAMP>`this'</SAMP>, then the
corresponding object value must be the same as the object on which we found
this verb; for example, if we are considering verbs on the player, then the
object value must be the player object.

</P>
<P>
Finally, recall that the argument specifier for the preposition is
either <SAMP>`none'</SAMP>, <SAMP>`any'</SAMP>, or one of several sets of prepositional
phrases, given above.  A specifier of <SAMP>`none'</SAMP> matches only if there
was no preposition found in the command.  A specifier of <SAMP>`any'</SAMP>
always matches, regardless of what preposition was found, if any.  If
the specifier is a set of prepositional phrases, then the one found must
be in that set for the specifier to match.

</P>
<P>
So, the server considers several objects in turn, checking each of their
verbs in turn, looking for the first one that meets all of the criteria
just explained.  If it finds one, then that is the verb whose program
will be executed for this command.  If not, then it looks for a verb
named <SAMP>`huh'</SAMP> on the room that the player is in; if one is found,
then that verb will be called.  This feature is useful for implementing
room-specific command parsing or error recovery.  If the server can't
even find a <SAMP>`huh'</SAMP> verb to run, it prints an error message like
<SAMP>`I couldn't understand that.'</SAMP> and the command is considered complete.

</P>
<P>
At long last, we have a program to run in response to the command typed by the
player.  When the code for the program begins execution, the following
built-in variables will have the indicated values:

</P>

<PRE>
player    an object, the player who typed the command
this      an object, the object on which this verb was found
caller    an object, the same as <SAMP>`player'</SAMP>
verb      a string, the first word of the command
argstr    a string, everything after the first word of the command
args      a list of strings, the words in <SAMP>`argstr'</SAMP>
dobjstr   a string, the direct object string found during parsing
dobj      an object, the direct object value found during matching
prepstr   a string, the prepositional phrase found during parsing
iobjstr   a string, the indirect object string
iobj      an object, the indirect object value
</PRE>

<P>
The value returned by the program, if any, is ignored by the server.

</P>


<H1><A NAME="SEC9" HREF="ProgrammersManual_toc.html#SEC9">The MOO Programming Language</A></H1>

<P>
MOO stands for "MUD, Object Oriented."  MUD, in turn, has been said to stand
for many different things, but I tend to think of it as "Multi-User Dungeon"
in the spirit of those ancient precursors to MUDs, Adventure and Zork.

</P>
<P>
MOO, the programming language, is a relatively small and simple
object-oriented language designed to be easy to learn for most
non-programmers; most complex systems still require some significant
programming ability to accomplish, however.

</P>
<P>
Having given you enough context to allow you to understand exactly what MOO
code is doing, I now explain what MOO code looks like and what it means.  I
begin with the syntax and semantics of expressions, those pieces of code that
have values.  After that, I cover statements, the next level of structure up
from expressions.  Next, I discuss the concept of a task, the kind of running
process initiated by players entering commands, among other causes.  Finally,
I list all of the built-in functions available to MOO code and describe what
they do.

</P>
<P>
First, though, let me mention comments.  You can include bits of text in your
MOO program that are ignored by the server.  The idea is to allow you to put
in notes to yourself and others about what the code is doing.  To do this,
begin the text of the comment with the two characters <SAMP>`/*'</SAMP> and end it
with the two characters <SAMP>`*/'</SAMP>; this is just like comments in the C
programming language.  Note that the server will completely ignore that text;
it will <EM>not</EM> be saved in the database.  Thus, such comments are only
useful in files of code that you maintain outside the database.

</P>
<P>
To include a more persistent comment in your code, try using a character
string literal as a statement.  For example, the sentence about peanut butter
in the following code is essentially ignored during execution but will be
maintained in the database:

</P>

<PRE>
for x in (players())
  "Grendel eats peanut butter!";
  player:tell(x.name, " (", x, ")");
endfor
</PRE>



<H2><A NAME="SEC10" HREF="ProgrammersManual_toc.html#SEC10">MOO Language Expressions</A></H2>

<P>
Expressions are those pieces of MOO code that generate values; for
example, the MOO code

<PRE>
3 + 4
</PRE>

<P>
is an expression that generates (or "has" or "returns") the value 7.
There are many kinds of expressions in MOO, all of them discussed below.

</P>



<H3><A NAME="SEC11" HREF="ProgrammersManual_toc.html#SEC11">Errors While Evaluating Expressions</A></H3>

<P>
Most kinds of expressions can, under some circumstances, cause an error to be
generated.  For example, the expression <CODE>x / y</CODE> will generate the error
<CODE>E_DIV</CODE> if <CODE>y</CODE> is equal to zero.  When an expression generates an
error, the behavior of the server is controlled by setting of the <SAMP>`d'</SAMP>
(debug) bit on the verb containing that expression.  If the <SAMP>`d'</SAMP> bit is not
set, then the error is effectively squelched immediately upon generation; the
error value is simply returned as the value of the expression that generated
it.

</P>

<BLOCKQUOTE>
<P>
<STRONG>Note:</STRONG> this error-squelching behavior is very error prone, since it
affects <EM>all</EM> errors, including ones the programmer may not have
anticipated.  The <SAMP>`d'</SAMP> bit exists only for historical reasons; it was once
the only way for MOO programmers to catch and handle errors.  The
error-catching expression and the <CODE>try</CODE>-<CODE>except</CODE> statement, both
described below, are far better ways of accomplishing the same thing.
</BLOCKQUOTE>

<P>
If the <SAMP>`d'</SAMP> bit is set, as it usually is, then the error is <STRONG>raised</STRONG>
and can be caught and handled either by code surrounding the expression in
question or by verbs higher up on the chain of calls leading to the current
verb.  If the error is not caught, then the server aborts the entire task and,
by default, prints a message to the current player.  See the descriptions of
the error-catching expression and the <CODE>try</CODE>-<CODE>except</CODE> statement for
the details of how errors can be caught, and the chapter on server assumptions
about the database for details on the handling of uncaught errors.

</P>


<H3><A NAME="SEC12" HREF="ProgrammersManual_toc.html#SEC12">Writing Values Directly in Verbs</A></H3>

<P>
The simplest kind of expression is a literal MOO value, just as
described in the section on values at the beginning of this document.
For example, the following are all expressions:

</P>

<PRE>
17
#893
"This is a character string."
E_TYPE
{"This", "is", "a", "list", "of", "words"}
</PRE>

<P>
In the case of lists, like the last example above, note that the list
expression contains other expressions, several character strings in this
case.  In general, those expressions can be of any kind at all, not
necessarily literal values.  For example,

<PRE>
{3 + 4, 3 - 4, 3 * 4}
</PRE>

<P>
is an expression whose value is the list <CODE>{7, -1, 12}</CODE>.

</P>


<H3><A NAME="SEC13" HREF="ProgrammersManual_toc.html#SEC13">Naming Values Within a Verb</A></H3>

<P>
As discussed earlier, it is possible to store values in properties on
objects; the properties will keep those values forever, or until another
value is explicitly put there.  Quite often, though, it is useful to
have a place to put a value for just a little while.  MOO provides local
variables for this purpose.

</P>
<P>
Variables are named places to hold values; you can get and set the value
in a given variable as many times as you like.  Variables are temporary,
though; they only last while a particular verb is running; after it
finishes, all of the variables given values there cease to exist and the
values are forgotten.

</P>
<P>
Variables are also "local" to a particular verb; every verb has its own
set of them.  Thus, the variables set in one verb are not visible to the
code of other verbs.

</P>
<P>
The name for a variable is made up entirely of letters, digits, and the
underscore character (<SAMP>`_'</SAMP>) and does not begin with a digit.  The
following are all valid variable names:

</P>

<PRE>
foo
_foo
this2that
M68000
two_words
This_is_a_very_long_multiword_variable_name
</PRE>

<P>
Note that, along with almost everything else in MOO, the case of the
letters in variable names is insignificant.  For example, these are all
names for the same variable:

</P>

<PRE>
fubar
Fubar
FUBAR
fUbAr
</PRE>

<P>
A variable name is itself an expression; its value is the value of the named
variable.  When a verb begins, almost no variables have values yet; if you try
to use the value of a variable that doesn't have one, the error value
<CODE>E_VARNF</CODE> is raised.  (MOO is unlike many other programming languages in
which one must `declare' each variable before using it; MOO has no such
declarations.)  The following variables always have values:

</P>

<PRE>
INT         FLOAT        OBJ
STR         LIST         ERR
player      this         caller
verb        args         argstr
dobj        dobjstr      prepstr
iobj        iobjstr      NUM
</PRE>

<P>
The values of some of these variables always start out the same:

</P>
<DL COMPACT>

<DT><CODE>INT</CODE>
<DD>
an integer, the type code for integers (see the description of the function
<CODE>typeof()</CODE>, below)
<DT><CODE>NUM</CODE>
<DD>
the same as <CODE>INT</CODE> (for historical reasons)
<DT><CODE>FLOAT</CODE>
<DD>
an integer, the type code for floating-point numbers
<DT><CODE>LIST</CODE>
<DD>
an integer, the type code for lists
<DT><CODE>STR</CODE>
<DD>
an integer, the type code for strings
<DT><CODE>OBJ</CODE>
<DD>
an integer, the type code for objects
<DT><CODE>ERR</CODE>
<DD>
an integer, the type code for error values
</DL>

<P>
For others, the general meaning of the value is consistent, though the
value itself is different for different situations:

</P>
<DL COMPACT>

<DT><CODE>player</CODE>
<DD>
an object, the player who typed the command that started the task that
involved running this piece of code.
<DT><CODE>this</CODE>
<DD>
an object, the object on which the currently-running verb was found.
<DT><CODE>caller</CODE>
<DD>
an object, the object on which the verb that called the
currently-running verb was found.  For the first verb called for a given
command, <SAMP>`caller'</SAMP> has the same value as <SAMP>`player'</SAMP>.
<DT><CODE>verb</CODE>
<DD>
a string, the name by which the currently-running verb was identified.
<DT><CODE>args</CODE>
<DD>
a list, the arguments given to this verb.  For the first verb called for
a given command, this is a list of strings, the words on the command
line.
</DL>

<P>
The rest of the so-called "built-in" variables are only really
meaningful for the first verb called for a given command.  Their
semantics is given in the discussion of command parsing, above.

</P>
<P>
To change what value is stored in a variable, use an <STRONG>assignment</STRONG>
expression:

</P>

<PRE>
<VAR>variable</VAR> = <VAR>expression</VAR>
</PRE>

<P>
For example, to change the variable named <SAMP>`x'</SAMP> to have the value 17,
you would write <SAMP>`x = 17'</SAMP> as an expression.  An assignment
expression does two things:

</P>

<UL>
<LI>

it changes the value of of the named variable, and
<LI>

it returns the new value of that variable.
</UL>

<P>
Thus, the expression

</P>

<PRE>
13 + (x = 17)
</PRE>

<P>
changes the value of <SAMP>`x'</SAMP> to be 17 and returns 30.

</P>


<H3><A NAME="SEC14" HREF="ProgrammersManual_toc.html#SEC14">Arithmetic Operators</A></H3>

<P>
All of the usual simple operations on numbers are available to MOO programs:

</P>

<PRE>
+    -    *    /    %
</PRE>

<P>
These are, in order, addition, subtraction, multiplication, division, and
remainder.  In the following table, the expressions on the left have the
corresponding values on the right:

</P>

<PRE>
5 + 2       =>   7
5 - 2       =>   3
5 * 2       =>   10
5 / 2       =>   2
5.0 / 2.0   =>   2.5
5 % 2       =>   1
5.0 % 2.0   =>   1.0
5 % -2      =>   1
-5 % 2      =>   -1
-5 % -2     =>   -1
-(5 + 2)    =>   -7
</PRE>

<P>
Note that integer division in MOO throws away the remainder and that the result
of the remainder operator (<SAMP>`%'</SAMP>) has the same sign as the left-hand
operand.  Also, note that <SAMP>`-'</SAMP> can be used without a left-hand operand to
negate a numeric expression.

</P>

<BLOCKQUOTE>
<P>
<EM>Fine point:</EM> Integers and floating-point numbers cannot be mixed in any
particular use of these arithmetic operators; unlike some other programming
languages, MOO does not automatically coerce integers into floating-point
numbers.  You can use the <CODE>tofloat()</CODE> function to perform an explicit
conversion.
</BLOCKQUOTE>

<P>
The <SAMP>`+'</SAMP> operator can also be used to append two strings.  The expression

</P>

<PRE>
"foo" + "bar"
</PRE>

<P>
has the value

</P>

<PRE>
"foobar"
</PRE>

<P>
Unless both operands to an arithmetic operator are numbers of the same kind
(or, for <SAMP>`+'</SAMP>, both strings), the error value <CODE>E_TYPE</CODE> is raised.  If
the right-hand operand for the division or remainder operators (<SAMP>`/'</SAMP> or
<SAMP>`%'</SAMP>) is zero, the error value <CODE>E_DIV</CODE> is raised.

</P>
<P>
MOO also supports the exponentiation operation, also known as "raising to a
power," using the <SAMP>`^'</SAMP> operator:

</P>

<PRE>
3 ^ 4       =>   81
3 ^ 4.5     error-->   E_TYPE
3.5 ^ 4     =>   150.0625
3.5 ^ 4.5   =>   280.741230801382
</PRE>

<P>
Note that if the first operand is an integer, then the second operand must also
be an integer.  If the first operand is a floating-point number, then the
second operand can be either kind of number.  Although it is legal to raise an
integer to a negative power, it is unlikely to be terribly useful.

</P>


<H3><A NAME="SEC15" HREF="ProgrammersManual_toc.html#SEC15">Comparing Values</A></H3>

<P>
Any two values can be compared for equality using <SAMP>`=='</SAMP> and
<SAMP>`!='</SAMP>.  The first of these returns 1 if the two values are equal and
0 otherwise; the second does the reverse:

</P>

<PRE>
3 == 4                              =>  0
3 != 4                              =>  1
3 == 3.0                            =>  0
"foo" == "Foo"                      =>  1
#34 != #34                          =>  0
{1, #34, "foo"} == {1, #34, "FoO"}  =>  1
E_DIV == E_TYPE                     =>  0
3 != "foo"                          =>  1
</PRE>

<P>
Note that integers and floating-point numbers are never equal to one another,
even in the `obvious' cases.  Also note that comparison of strings (and list
values containing strings) is case-insensitive; that is, it does not
distinguish between the upper- and lower-case version of letters.  To test two
values for case-sensitive equality, use the <SAMP>`equal'</SAMP> function described
later.

</P>

<BLOCKQUOTE>
<P>
<STRONG>Warning</STRONG>: It is easy (and very annoying) to confuse the
equality-testing operator (<SAMP>`=='</SAMP>) with the assignment operator (<SAMP>`='</SAMP>),
leading to nasty, hard-to-find bugs.  Don't do this.
</BLOCKQUOTE>

<P>
Numbers, object numbers, strings, and error values can also be compared
for ordering purposes using the following operators:

</P>

<PRE>
&#60;       &#60;=      &#62;=      &#62;
</PRE>

<P>
meaning "less than," "less than or equal," "greater than or
equal," and "greater than," respectively.  As with the equality
operators, these return 1 when their operands are in the appropriate
relation and 0 otherwise:

</P>

<PRE>
3 &#60; 4           =>  1
3 &#60; 4.0         error-->  E_TYPE
#34 &#62;= #32      =>  1
"foo" &#60;= "Boo"  =>  0
E_DIV &#62; E_TYPE  =>  1
</PRE>

<P>
Note that, as with the equality operators, strings are compared
case-insensitively.  To perform a case-sensitive string comparison, use the
<SAMP>`strcmp'</SAMP> function described later.  Also note that the error values are
ordered as given in the table in the section on values.  If the operands to
these four comparison operators are of different types (even integers and
floating-point numbers are considered different types), or if they are lists,
then <CODE>E_TYPE</CODE> is raised.

</P>


<H3><A NAME="SEC16" HREF="ProgrammersManual_toc.html#SEC16">Values as True and False</A></H3>

<P>
There is a notion in MOO of <STRONG>true</STRONG> and <STRONG>false</STRONG> values; every value
is one or the other.  The true values are as follows:

</P>

<UL>
<LI>

all integers other than zero,
<LI>

all floating-point numbers not equal to <CODE>0.0</CODE>,
<LI>

all non-empty strings (i.e., other than <SAMP>`""'</SAMP>), and
<LI>

all non-empty lists (i.e., other than <SAMP>`{}'</SAMP>).
</UL>

<P>
All other values are false:

</P>

<UL>
<LI>

the integer zero,
<LI>

the floating-point numbers <CODE>0.0</CODE> and <CODE>-0.0</CODE>,
<LI>

the empty string (<SAMP>`""'</SAMP>),
<LI>

the empty list (<SAMP>`{}'</SAMP>),
<LI>

all object numbers, and
<LI>

all error values.
</UL>

<P>
There are four kinds of expressions and two kinds of statements that depend
upon this classification of MOO values.  In describing them, I sometimes refer
to the <STRONG>truth value</STRONG> of a MOO value; this is just <STRONG>true</STRONG> or
<STRONG>false</STRONG>, the category into which that MOO value is classified.

</P>
<P>
The conditional expression in MOO has the following form:

</P>

<PRE>
<VAR>expression-1</VAR> ? <VAR>expression-2</VAR> | <VAR>expression-3</VAR>
</PRE>

<P>
First, <VAR>expression-1</VAR> is evaluated.  If it returns a true value, then
<VAR>expression-2</VAR> is evaluated and whatever it returns is returned as the
value of the conditional expression as a whole.  If <VAR>expression-1</VAR> returns
a false value, then <VAR>expression-3</VAR> is evaluated instead and its value is
used as that of the conditional expression.

</P>

<PRE>
1 ? 2 | 3           =>  2
0 ? 2 | 3           =>  3
"foo" ? 17 | {#34}  =>  17
</PRE>

<P>
Note that only one of <VAR>expression-2</VAR> and <VAR>expression-3</VAR> is evaluated,
never both.

</P>
<P>
To negate the truth value of a MOO value, use the <SAMP>`!'</SAMP> operator:

</P>

<PRE>
! <VAR>expression</VAR>
</PRE>

<P>
If the value of <VAR>expression</VAR> is true, <SAMP>`!'</SAMP> returns 0; otherwise, it
returns 1:

</P>

<PRE>
! "foo"     =>  0
! (3 &#62;= 4)  =>  1
</PRE>

<P>
The negation operator is usually read as "not."

</P>
<P>
It is frequently useful to test more than one condition to see if some or all
of them are true.  MOO provides two operators for this:

</P>

<PRE>
<VAR>expression-1</VAR> &#38;&#38; <VAR>expression-2</VAR>
<VAR>expression-1</VAR> || <VAR>expression-2</VAR>
</PRE>

<P>
These operators are usually read as "and" and "or," respectively.

</P>
<P>
The <SAMP>`&#38;&#38;'</SAMP> operator first evaluates <VAR>expression-1</VAR>.  If it returns a
true value, then <VAR>expression-2</VAR> is evaluated and its value becomes the
value of the <SAMP>`&#38;&#38;'</SAMP> expression as a whole; otherwise, the value of
<VAR>expression-1</VAR> is used as the value of the <SAMP>`&#38;&#38;'</SAMP> expression.  Note
that <VAR>expression-2</VAR> is only evaluated if <VAR>expression-1</VAR> returns a true
value.  The <SAMP>`&#38;&#38;'</SAMP> expression is equivalent to the conditional expression

</P>

<PRE>
<VAR>expression-1</VAR> ? <VAR>expression-2</VAR> | <VAR>expression-1</VAR>
</PRE>

<P>
except that <VAR>expression-1</VAR> is only evaluated once.

</P>
<P>
The <SAMP>`||'</SAMP> operator works similarly, except that <VAR>expression-2</VAR> is
evaluated only if <VAR>expression-1</VAR> returns a false value.  It is equivalent
to the conditional expression

</P>

<PRE>
<VAR>expression-1</VAR> ? <VAR>expression-1</VAR> | <VAR>expression-2</VAR>
</PRE>

<P>
except that, as with <SAMP>`&#38;&#38;'</SAMP>, <VAR>expression-1</VAR> is only evaluated once.

</P>
<P>
These two operators behave very much like "and" and "or" in English:

</P>

<PRE>
1 &#38;&#38; 1                  =>  1
0 &#38;&#38; 1                  =>  0
0 &#38;&#38; 0                  =>  0
1 || 1                  =>  1
0 || 1                  =>  1
0 || 0                  =>  0
17 &#60;= 23  &#38;&#38;  23 &#60;= 27  =>  1
</PRE>



<H3><A NAME="SEC17" HREF="ProgrammersManual_toc.html#SEC17">Indexing into Lists and Strings</A></H3>

<P>
Both strings and lists can be seen as ordered sequences of MOO values.  In the
case of strings, each is a sequence of single-character strings; that is, one
can view the string <CODE>"bar"</CODE> as a sequence of the strings <CODE>"b"</CODE>,
<CODE>"a"</CODE>, and <CODE>"r"</CODE>.  MOO allows you to refer to the elements of lists
and strings by number, by the <STRONG>index</STRONG> of that element in the list or
string.  The first element in a list or string has index 1, the second has
index 2, and so on.

</P>



<H4><A NAME="SEC18" HREF="ProgrammersManual_toc.html#SEC18">Extracting an Element from a List or String</A></H4>

<P>
The indexing expression in MOO extracts a specified element from a list or
string:

</P>

<PRE>
<VAR>expression-1</VAR>[<VAR>expression-2</VAR>]
</PRE>

<P>
First, <VAR>expression-1</VAR> is evaluated; it must return a list or a string (the
<STRONG>sequence</STRONG>).  Then, <VAR>expression-2</VAR> is evaluated and must return an
integer (the <STRONG>index</STRONG>).  If either of the expressions returns some other type
of value, <CODE>E_TYPE</CODE> is returned.  The index must be between 1 and the
length of the sequence, inclusive; if it is not, then <CODE>E_RANGE</CODE> is raised.
The value of the indexing expression is the index'th element in the sequence.
Anywhere within <VAR>expression-2</VAR>, you can use the symbol <CODE>$</CODE> as an
expression returning the length of the value of <VAR>expression-1</VAR>.

</P>

<PRE>
"fob"[2]                =>  "o"
"fob"[1]                =>  "f"
{#12, #23, #34}[$ - 1]  =>  #23
</PRE>

<P>
Note that there are no legal indices for the empty string or list, since
there are no integers between 1 and 0 (the length of the empty string or
list).

</P>

<BLOCKQUOTE>
<P>
<EM>Fine point:</EM> The <CODE>$</CODE> expression actually returns the length of the
value of the expression just before the nearest enclosing <CODE>[...]</CODE>
indexing or subranging brackets.  For example:

<PRE>
"frob"[{3, 2, 4}[$]]     =>  "b"
</PRE>

</BLOCKQUOTE>



<H4><A NAME="SEC19" HREF="ProgrammersManual_toc.html#SEC19">Replacing an Element of a List or String</A></H4>

<P>
It often happens that one wants to change just one particular slot of a list or
string, which is stored in a variable or a property.  This can be done
conveniently using an <STRONG>indexed assignment</STRONG> having one of the following
forms:

</P>

<PRE>
<VAR>variable</VAR>[<VAR>index-expr</VAR>] = <VAR>result-expr</VAR>
<VAR>object-expr</VAR>.<VAR>name</VAR>[<VAR>index-expr</VAR>] = <VAR>result-expr</VAR>
<VAR>object-expr</VAR>.(<VAR>name-expr</VAR>)[<VAR>index-expr</VAR>] = <VAR>result-expr</VAR>
$<VAR>name</VAR>[<VAR>index-expr</VAR>] = <VAR>result-expr</VAR>
</PRE>

<P>
The first form writes into a variable, and the last three forms write into a
property.  The usual errors (<CODE>E_TYPE</CODE>, <CODE>E_INVIND</CODE>, <CODE>E_PROPNF</CODE>
and <CODE>E_PERM</CODE> for lack of read/write permission on the property) may be
raised, just as in reading and writing any object property; see the
discussion of object property expressions below for details.  Correspondingly,
if <VAR>variable</VAR> does not yet have a value (i.e., it has never been assigned
to), <CODE>E_VARNF</CODE> will be raised.

</P>
<P>
If <VAR>index-expr</VAR> is not an integer, or if the value of <VAR>variable</VAR> or the
property is not a list or string, <CODE>E_TYPE</CODE> is raised.  If
<VAR>result-expr</VAR> is a string, but not of length 1, <CODE>E_INVARG</CODE> is
raised.  Now suppose <VAR>index-expr</VAR> evaluates to an integer <VAR>k</VAR>.  If
<VAR>k</VAR> is outside the range of the list or string (i.e.  smaller than 1 or
greater than the length of the list or string), <CODE>E_RANGE</CODE> is raised.
Otherwise, the actual assignment takes place.  For lists, the variable or the
property is assigned a new list that is identical to the original one except at
the <VAR>k</VAR>-th position, where the new list contains the result of
<VAR>result-expr</VAR> instead.  For strings, the variable or the property is
assigned a new string that is identical to the original one, except the
<VAR>k</VAR>-th character is changed to be <VAR>result-expr</VAR>.

</P>
<P>
The assignment expression itself returns the value of <VAR>result-expr</VAR>.  For
the following examples, assume that <CODE>l</CODE> initially contains the list
<CODE>{1, 2, 3}</CODE> and that <CODE>s</CODE> initially contains the string "foobar":

</P>

<PRE>
l[5] = 3          error-->   E_RANGE
l["first"] = 4    error-->   E_TYPE
s[3] = "baz"      error-->   E_INVARG
l[2] = l[2] + 3   =>   5
l                 =>   {1, 5, 3}
l[2] = "foo"      =>   "foo"
l                 =>   {1, "foo", 3}
s[2] = "u"        =>   "u"
s                 =>   "fuobar"
s[$] = "z"        =>   "z"
s                 =>   "fuobaz"
</PRE>

<P>
Note that the <CODE>$</CODE> expression may also be used in indexed assignments with
the same meaning as before.

</P>

<BLOCKQUOTE>
<P>
<EM>Fine point:</EM> After an indexed assignment, the variable or property
contains a <EM>new</EM> list or string, a copy of the original list in all but
the <VAR>k</VAR>-th place, where it contains a new value.  In programming-language
jargon, the original list is not mutated, and there is no aliasing.  (Indeed,
no MOO value is mutable and no aliasing ever occurs.)
</BLOCKQUOTE>

<P>
In the list case, indexed assignment can be nested to many levels, to work on
nested lists.  Assume that <CODE>l</CODE> initially contains the list

</P>

<PRE>
{{1, 2, 3}, {4, 5, 6}, "foo"}
</PRE>

<P>
in the following examples:

</P>

<PRE>
l[7] = 4             error-->   E_RANGE
l[1][8] = 35         error-->   E_RANGE
l[3][2] = 7          error-->   E_TYPE
l[1][1][1] = 3       error-->   E_TYPE
l[2][2] = -l[2][2]   =>   -5
l                    =>   {{1, 2, 3}, {4, -5, 6}, "foo"}
l[2] = "bar"         =>   "bar"
l                    =>   {{1, 2, 3}, "bar", "foo"}
l[2][$] = "z"        =>   "z"
l                    =>   {{1, 2, 3}, "baz", "foo"}
</PRE>

<P>
The first two examples raise <CODE>E_RANGE</CODE> because 7 is out of the range of
<CODE>l</CODE> and 8 is out of the range of <CODE>l[1]</CODE>.  The next two examples
raise <CODE>E_TYPE</CODE> because <CODE>l[3]</CODE> and <CODE>l[1][1]</CODE> are not lists.

</P>


<H4><A NAME="SEC20" HREF="ProgrammersManual_toc.html#SEC20">Extracting a Subsequence of a List or String</A></H4>

<P>
The range expression extracts a specified subsequence from a list or string:

</P>

<PRE>
<VAR>expression-1</VAR>[<VAR>expression-2</VAR>..<VAR>expression-3</VAR>]
</PRE>

<P>
The three expressions are evaluated in order.  <VAR>Expression-1</VAR> must return a
list or string (the <STRONG>sequence</STRONG>) and the other two expressions must return
integers (the <STRONG>low</STRONG> and <STRONG>high</STRONG> indices, respectively); otherwise,
<CODE>E_TYPE</CODE> is raised.  The <CODE>$</CODE> expression can be used in either or both
of <VAR>expression-2</VAR> and <VAR>expression-3</VAR> just as before, meaning the length
of the value of <VAR>expression-1</VAR>.

</P>
<P>
If the low index is greater than the high index, then the empty string or list
is returned, depending on whether the sequence is a string or a list.
Otherwise, both indices must be between 1 and the length of the sequence;
<CODE>E_RANGE</CODE> is raised if they are not.  A new list or string is returned
that contains just the elements of the sequence with indices between the low
and high bounds.

</P>

<PRE>
"foobar"[2..$]                       =>  "oobar"
"foobar"[3..3]                       =>  "o"
"foobar"[17..12]                     =>  ""
{"one", "two", "three"}[$ - 1..$]    =>  {"two", "three"}
{"one", "two", "three"}[3..3]        =>  {"three"}
{"one", "two", "three"}[17..12]      =>  {}
</PRE>



<H4><A NAME="SEC21" HREF="ProgrammersManual_toc.html#SEC21">Replacing a Subsequence of a List or String</A></H4>

<P>
  The subrange assigment replaces a specified subsequence of a list or string
with a supplied subsequence.  The allowed forms are:

</P>

<PRE>
<VAR>variable</VAR>[<VAR>start-index-expr</VAR>..<VAR>end-index-expr</VAR>] = <VAR>result-expr</VAR>
<VAR>object-expr</VAR>.<VAR>name</VAR>[<VAR>start-index-expr</VAR>..<VAR>end-index-expr</VAR>] = <VAR>result-expr</VAR>
<VAR>object-expr</VAR>.(<VAR>name-expr</VAR>)[<VAR>start-index-expr</VAR>..<VAR>end-index-expr</VAR>] = <VAR>result-expr</VAR>
$<VAR>name</VAR>[<VAR>start-index-expr</VAR>..<VAR>end-index-expr</VAR>] = <VAR>result-expr</VAR>
</PRE>

<P>
As with indexed assigments, the first form writes into a variable, and the last
three forms write into a property.  The same errors (<CODE>E_TYPE</CODE>,
<CODE>E_INVIND</CODE>, <CODE>E_PROPNF</CODE> and <CODE>E_PERM</CODE> for lack of read/write
permission on the property) may be raised.  If <VAR>variable</VAR> does not yet have
a value (i.e., it has never been assigned to), <CODE>E_VARNF</CODE> will be raised.
As before, the <CODE>$</CODE> expression can be used in either <VAR>start-index-expr</VAR>
or <VAR>end-index-expr</VAR>, meaning the length of the original value of the
expression just before the <CODE>[...]</CODE> part.

</P>
<P>
If <VAR>start-index-expr</VAR> or <VAR>end-index-expr</VAR> is not an integer, if the value
of <VAR>variable</VAR> or the property is not a list or string, or <VAR>result-expr</VAR>
is not the same type as <VAR>variable</VAR> or the property, <CODE>E_TYPE</CODE> is
raised.  <CODE>E_RANGE</CODE> is raised if <VAR>end-index-expr</VAR> is less than zero
or if <VAR>start-index-expr</VAR> is greater than the length of the list or string
plus one.  Note: the length of <VAR>result-expr</VAR> does not need to be the same
as the length of the specified range.

</P>
<P>
In precise terms, the subrange assigment

<PRE>
<VAR>v</VAR>[<VAR>start</VAR>..<VAR>end</VAR>] = <VAR>value</VAR>
</PRE>

<P>
is equivalent to

<PRE>
<VAR>v</VAR> = {@<VAR>v</VAR>[1..<VAR>start</VAR> - 1], @<VAR>value</VAR>, @<VAR>v</VAR>[<VAR>end</VAR> + 1..$]}
</PRE>

<P>
if <VAR>v</VAR> is a list and to

<PRE>
<VAR>v</VAR> = <VAR>v</VAR>[1..<VAR>start</VAR> - 1] + <VAR>value</VAR> + <VAR>v</VAR>[<VAR>end</VAR> + 1..$]
</PRE>

<P>
if <VAR>v</VAR> is a string.

</P>
<P>
The assigment expression itself returns the value of <VAR>result-expr</VAR>.  For
the following examples, assume that <CODE>l</CODE> initially contains the list
<CODE>{1, 2, 3}</CODE> and that <CODE>s</CODE> initially contains the string "foobar":

</P>

<PRE>
l[5..6] = {7, 8}       error-->   E_RANGE
l[2..3] = 4            error-->   E_TYPE
l[#2..3] = {7}         error-->   E_TYPE
s[2..3] = {6}          error-->   E_TYPE
l[2..3] = {6, 7, 8, 9} =>   {6, 7, 8, 9}
l                      =>   {1, 6, 7, 8, 9}
l[2..1] = {10, "foo"}  =>   {10, "foo"}
l                      =>   {1, 10, "foo", 6, 7, 8, 9}
l[3][2..$] = "u"       =>   "u"
l                      =>   {1, 10, "fu", 6, 7, 8, 9}
s[7..12] = "baz"       =>   "baz"
s                      =>   "foobarbaz"
s[1..3] = "fu"         =>   "fu"
s                      =>   "fubarbaz"
s[1..0] = "test"       =>   "test"
s                      =>   "testfubarbaz"
</PRE>



<H3><A NAME="SEC22" HREF="ProgrammersManual_toc.html#SEC22">Other Operations on Lists</A></H3>

<P>
As was mentioned earlier, lists can be constructed by writing a
comma-separated sequence of expressions inside curly braces:

</P>

<PRE>
{<VAR>expression-1</VAR>, <VAR>expression-2</VAR>, ..., <VAR>expression-N</VAR>}
</PRE>

<P>
The resulting list has the value of <VAR>expression-1</VAR> as its first element,
that of <VAR>expression-2</VAR> as the second, etc.

</P>

<PRE>
{3 &#60; 4, 3 &#60;= 4, 3 &#62;= 4, 3 &#62; 4}  =>  {1, 1, 0, 0}
</PRE>

<P>
Additionally, one may precede any of these expressions by the splicing
operator, <SAMP>`@'</SAMP>.  Such an expression must return a list; rather than the
old list itself becoming an element of the new list, all of the elements of
the old list are included in the new list.  This concept is easy to
understand, but hard to explain in words, so here are some examples.  For
these examples, assume that the variable <CODE>a</CODE> has the value <CODE>{2, 3,
4}</CODE> and that <CODE>b</CODE> has the value <CODE>{"Foo", "Bar"}</CODE>:

</P>

<PRE>
{1, a, 5}   =>  {1, {2, 3, 4}, 5}
{1, @a, 5}  =>  {1, 2, 3, 4, 5}
{a, @a}     =>  {{2, 3, 4}, 2, 3, 4}
{@a, @b}    =>  {2, 3, 4, "Foo", "Bar"}
</PRE>

<P>
If the splicing operator (<SAMP>`@'</SAMP>) precedes an expression whose value
is not a list, then <CODE>E_TYPE</CODE> is raised as the value of the list
construction as a whole.

</P>
<P>
The list membership expression tests whether or not a given MOO value is an
element of a given list and, if so, with what index:

</P>

<PRE>
<VAR>expression-1</VAR> in <VAR>expression-2</VAR>
</PRE>

<P>
<VAR>Expression-2</VAR> must return a list; otherwise, <CODE>E_TYPE</CODE> is raised.
If the value of <VAR>expression-1</VAR> is in that list, then the index of its first
occurrence in the list is returned; otherwise, the <SAMP>`in'</SAMP> expression returns
0.

</P>

<PRE>
2 in {5, 8, 2, 3}               =>  3
7 in {5, 8, 2, 3}               =>  0
"bar" in {"Foo", "Bar", "Baz"}  =>  2
</PRE>

<P>
Note that the list membership operator is case-insensitive in comparing
strings, just like the comparison operators.  To perform a case-sensitive list
membership test, use the <SAMP>`is_member'</SAMP> function described later.  Note also
that since it returns zero only if the given value is not in the given list,
the <SAMP>`in'</SAMP> expression can be used either as a membership test or as an
element locator.

</P>


<H3><A NAME="SEC23" HREF="ProgrammersManual_toc.html#SEC23">Spreading List Elements Among Variables</A></H3>

<P>
It is often the case in MOO programming that you will want to access the
elements of a list individually, with each element stored in a separate
variables.  This desire arises, for example, at the beginning of almost every
MOO verb, since the arguments to all verbs are delivered all bunched together
in a single list.  In such circumstances, you <EM>could</EM> write statements
like these:

</P>

<PRE>
first = args[1];
second = args[2];
if (length(args) &#62; 2)
  third = args[3];
else
  third = 0;
endif
</PRE>

<P>
This approach gets pretty tedious, both to read and to write, and it's prone to
errors if you mistype one of the indices.  Also, you often want to check
whether or not any <EM>extra</EM> list elements were present, adding to the
tedium.

</P>
<P>
MOO provides a special kind of assignment expression, called <STRONG>scattering
assignment</STRONG> made just for cases such as these.  A scattering assignment
expression looks like this:

</P>

<PRE>
{<VAR>target</VAR>, ...} = <VAR>expr</VAR>
</PRE>

<P>
where each <VAR>target</VAR> describes a place to store elements of the list that
results from evaluating <VAR>expr</VAR>.  A <VAR>target</VAR> has one of the following
forms:

</P>
<DL COMPACT>

<DT><CODE><VAR>variable</VAR></CODE>
<DD>
This is the simplest target, just a simple variable; the list element in the
corresponding position is assigned to the variable.  This is called a
<STRONG>required</STRONG> target, since the assignment is required to put one of the list
elements into the variable.

<DT><CODE>?<VAR>variable</VAR></CODE>
<DD>
This is called an <STRONG>optional</STRONG> target, since it doesn't always get assigned
an element.  If there are any list elements left over after all of the required
targets have been accounted for (along with all of the other optionals to the
left of this one), then this variable is treated like a required one and the
list element in the corresponding position is assigned to the variable.  If
there aren't enough elements to assign one to this target, then no assignment
is made to this variable, leaving it with whatever its previous value was.

<DT><CODE>?<VAR>variable</VAR> = <VAR>default-expr</VAR></CODE>
<DD>
This is also an optional target, but if there aren't enough list elements
available to assign one to this target, the result of evaluating
<VAR>default-expr</VAR> is assigned to it instead.  Thus, <VAR>default-expr</VAR>
provides a <STRONG>default value</STRONG> for the variable.  The default value expressions
are evaluated and assigned working from left to right <EM>after</EM> all of the
other assignments have been performed.

<DT><CODE>@<VAR>variable</VAR></CODE>
<DD>
By analogy with the <CODE>@</CODE> syntax in list construction, this variable is
assigned a list of all of the `leftover' list elements in this part of the list
after all of the other targets have been filled in.  It is assigned the empty
list if there aren't any elements left over.  This is called a <STRONG>rest</STRONG>
target, since it gets the rest of the elements.  There may be at most one rest
target in each scattering assignment expression.
</DL>

<P>
If there aren't enough list elements to fill all of the required targets, or if
there are more than enough to fill all of the required and optional targets but
there isn't a rest target to take the leftover ones, then <CODE>E_ARGS</CODE> is
raised.

</P>
<P>
Here are some examples of how this works.  Assume first that the verb
<CODE>me:foo()</CODE> contains the following code:

</P>

<PRE>
b = c = e = 17;
{a, ?b, ?c = 8, @d, ?e = 9, f} = args;
return {a, b, c, d, e, f};
</PRE>

<P>
Then the following calls return the given values:

</P>

<PRE>
me:foo(1)                        error-->   E_ARGS
me:foo(1, 2)                     =>   {1, 17, 8, {}, 9, 2}
me:foo(1, 2, 3)                  =>   {1, 2, 8, {}, 9, 3}
me:foo(1, 2, 3, 4)               =>   {1, 2, 3, {}, 9, 4}
me:foo(1, 2, 3, 4, 5)            =>   {1, 2, 3, {}, 4, 5}
me:foo(1, 2, 3, 4, 5, 6)         =>   {1, 2, 3, {4}, 5, 6}
me:foo(1, 2, 3, 4, 5, 6, 7)      =>   {1, 2, 3, {4, 5}, 6, 7}
me:foo(1, 2, 3, 4, 5, 6, 7, 8)   =>   {1, 2, 3, {4, 5, 6}, 7, 8}
</PRE>

<P>
Using scattering assignment, the example at the begining of this section could
be rewritten more simply, reliably, and readably:

</P>

<PRE>
{first, second, ?third = 0} = args;
</PRE>

<P>
It is good MOO programming style to use a scattering assignment at the top of
nearly every verb, since it shows so clearly just what kinds of arguments the
verb expects.

</P>


<H3><A NAME="SEC24" HREF="ProgrammersManual_toc.html#SEC24">Getting and Setting the Values of Properties</A></H3>

<P>
Usually, one can read the value of a property on an object with a simple
expression:

</P>

<PRE>
<VAR>expression</VAR>.<VAR>name</VAR>
</PRE>

<P>
<VAR>Expression</VAR> must return an object number; if not, <CODE>E_TYPE</CODE> is
raised.  If the object with that number does not exist, <CODE>E_INVIND</CODE> is
raised.  Otherwise, if the object does not have a property with that name,
then <CODE>E_PROPNF</CODE> is raised.  Otherwise, if the named property is not
readable by the owner of the current verb, then <CODE>E_PERM</CODE> is raised.
Finally, assuming that none of these terrible things happens, the value of the
named property on the given object is returned.

</P>
<P>
I said "usually" in the paragraph above because that simple expression only
works if the name of the property obeys the same rules as for the names of
variables (i.e., consists entirely of letters, digits, and underscores, and
doesn't begin with a digit).  Property names are not restricted to this set,
though.  Also, it is sometimes useful to be able to figure out what property
to read by some computation.  For these more general uses, the following
syntax is also allowed:

</P>

<PRE>
<VAR>expression-1</VAR>.(<VAR>expression-2</VAR>)
</PRE>

<P>
As before, <VAR>expression-1</VAR> must return an object number.  <VAR>Expression-2</VAR>
must return a string, the name of the property to be read; <CODE>E_TYPE</CODE>
is raised otherwise.  Using this syntax, any property can be read,
regardless of its name.

</P>
<P>
Note that, as with almost everything in MOO, case is not significant in the
names of properties.  Thus, the following expressions are all equivalent:

</P>

<PRE>
foo.bar
foo.Bar
foo.("bAr")
</PRE>

<P>
The LambdaCore database uses several properties on <CODE>#0</CODE>, the <STRONG>system
object</STRONG>, for various special purposes.  For example, the value of
<CODE>#0.room</CODE> is the "generic room" object, <CODE>#0.exit</CODE> is the "generic
exit" object, etc.  This allows MOO programs to refer to these useful objects
more easily (and more readably) than using their object numbers directly.  To
make this usage even easier and more readable, the expression

</P>

<PRE>
$<VAR>name</VAR>
</PRE>

<P>
(where <VAR>name</VAR> obeys the rules for variable names) is an abbreviation for

</P>

<PRE>
#0.<VAR>name</VAR>
</PRE>

<P>
Thus, for example, the value <CODE>$nothing</CODE> mentioned earlier is really
<CODE>#-1</CODE>, the value of <CODE>#0.nothing</CODE>.

</P>
<P>
As with variables, one uses the assignment operator (<SAMP>`='</SAMP>) to change the
value of a property.  For example, the expression

</P>

<PRE>
14 + (#27.foo = 17)
</PRE>

<P>
changes the value of the <SAMP>`foo'</SAMP> property of the object numbered 27 to be
17 and then returns 31.  Assignments to properties check that the owner of the
current verb has write permission on the given property, raising
<CODE>E_PERM</CODE> otherwise.  Read permission is not required.

</P>


<H3><A NAME="SEC25" HREF="ProgrammersManual_toc.html#SEC25">Calling Built-in Functions and Other Verbs</A></H3>

<P>
MOO provides a large number of useful functions for performing a wide
variety of operations; a complete list, giving their names, arguments,
and semantics, appears in a separate section later.  As an example to
give you the idea, there is a function named <SAMP>`length'</SAMP> that returns
the length of a given string or list.

</P>
<P>
The syntax of a call to a function is as follows:

</P>

<PRE>
<VAR>name</VAR>(<VAR>expr-1</VAR>, <VAR>expr-2</VAR>, ..., <VAR>expr-N</VAR>)
</PRE>

<P>
where <VAR>name</VAR> is the name of one of the built-in functions.  The
expressions between the parentheses, called <STRONG>arguments</STRONG>, are each
evaluated in turn and then given to the named function to use in its
appropriate way.  Most functions require that a specific number of arguments
be given; otherwise, <CODE>E_ARGS</CODE> is raised.  Most also require that
certain of the arguments have certain specified types (e.g., the
<CODE>length()</CODE> function requires a list or a string as its argument);
<CODE>E_TYPE</CODE> is raised if any argument has the wrong type.

</P>
<P>
As with list construction, the splicing operator <SAMP>`@'</SAMP> can precede
any argument expression.  The value of such an expression must be a
list; <CODE>E_TYPE</CODE> is raised otherwise.  The elements of this list
are passed as individual arguments, in place of the list as a whole.

</P>
<P>
Verbs can also call other verbs, usually using this syntax:

</P>

<PRE>
<VAR>expr-0</VAR>:<VAR>name</VAR>(<VAR>expr-1</VAR>, <VAR>expr-2</VAR>, ..., <VAR>expr-N</VAR>)
</PRE>

<P>
<VAR>Expr-0</VAR> must return an object number; <CODE>E_TYPE</CODE> is raised otherwise.
If the object with that number does not exist, <CODE>E_INVIND</CODE> is raised.  If
this task is too deeply nested in verbs calling verbs calling verbs, then
<CODE>E_MAXREC</CODE> is raised; the default limit is 50 levels, but this can be
changed from within the database; see the chapter on server assumptions about
the database for details.  If neither the object nor any of its ancestors
defines a verb matching the given name, <CODE>E_VERBNF</CODE> is raised.
Otherwise, if none of these nasty things happens, the named verb on the given
object is called; the various built-in variables have the following initial
values in the called verb:

</P>
<DL COMPACT>

<DT><CODE>this</CODE>
<DD>
an object, the value of <VAR>expr-0</VAR>
<DT><CODE>verb</CODE>
<DD>
a string, the <VAR>name</VAR> used in calling this verb
<DT><CODE>args</CODE>
<DD>
a list, the values of <VAR>expr-1</VAR>, <VAR>expr-2</VAR>, etc.
<DT><CODE>caller</CODE>
<DD>
an object, the value of <CODE>this</CODE> in the calling verb
<DT><CODE>player</CODE>
<DD>
an object, the same value as it had initially in the calling verb or, if the
calling verb is running with wizard permissions, the same as the current value
in the calling verb.
</DL>

<P>
All other built-in variables (<CODE>argstr</CODE>, <CODE>dobj</CODE>, etc.) are initialized
with the same values they have in the calling verb.

</P>
<P>
As with the discussion of property references above, I said "usually" at the
beginning of the previous paragraph because that syntax is only allowed when
the <VAR>name</VAR> follows the rules for allowed variable names.  Also as with
property reference, there is a syntax allowing you to compute the name of the
verb:

</P>

<PRE>
<VAR>expr-0</VAR>:(<VAR>expr-00</VAR>)(<VAR>expr-1</VAR>, <VAR>expr-2</VAR>, ..., <VAR>expr-N</VAR>)
</PRE>

<P>
The expression <VAR>expr-00</VAR> must return a string; <CODE>E_TYPE</CODE> is raised
otherwise.

</P>
<P>
The splicing operator (<SAMP>`@'</SAMP>) can be used with verb-call arguments,
too, just as with the arguments to built-in functions.

</P>
<P>
In many databases, a number of important verbs are defined on <CODE>#0</CODE>, the
<STRONG>system object</STRONG>.  As with the <SAMP>`$foo'</SAMP> notation for properties on
<CODE>#0</CODE>, the server defines a special syntax for calling verbs on <CODE>#0</CODE>:

</P>

<PRE>
$<VAR>name</VAR>(<VAR>expr-1</VAR>, <VAR>expr-2</VAR>, ..., <VAR>expr-N</VAR>)
</PRE>

<P>
(where <VAR>name</VAR> obeys the rules for variable names) is an abbreviation for

</P>

<PRE>
#0:<VAR>name</VAR>(<VAR>expr-1</VAR>, <VAR>expr-2</VAR>, ..., <VAR>expr-N</VAR>)
</PRE>



<H3><A NAME="SEC26" HREF="ProgrammersManual_toc.html#SEC26">Catching Errors in Expressions</A></H3>

<P>
It is often useful to be able to <STRONG>catch</STRONG> an error that an expression
raises, to keep the error from aborting the whole task, and to keep on running
as if the expression had returned some other value normally.  The following
expression accomplishes this:

</P>

<PRE>
` <VAR>expr-1</VAR> ! <VAR>codes</VAR> =&#62; <VAR>expr-2</VAR> '
</PRE>

<P>
<STRONG>Note:</STRONG> the open- and close-quotation marks in the previous line are
really part of the syntax; you must actually type them as part of your MOO
program for this kind of expression.

</P>
<P>
The <VAR>codes</VAR> part is either the keyword <CODE>ANY</CODE> or else a
comma-separated list of expressions, just like an argument list.  As in an
argument list, the splicing operator (<SAMP>`@'</SAMP>) can be used here.  The
<CODE>=&#62; <VAR>expr-2</VAR></CODE> part of the error-catching expression is optional.

</P>
<P>
First, the <VAR>codes</VAR> part is evaluated, yielding a list of error codes that
should be caught if they're raised; if <VAR>codes</VAR> is <CODE>ANY</CODE>, then it is
equivalent to the list of all possible MOO values.

</P>
<P>
Next, <VAR>expr-1</VAR> is evaluated.  If it evaluates normally, without raising an
error, then its value becomes the value of the entire error-catching
expression.  If evaluating <VAR>expr-1</VAR> results in an error being raised, then
call that error <VAR>E</VAR>.  If <VAR>E</VAR> is in the list resulting from evaluating
<VAR>codes</VAR>, then <VAR>E</VAR> is considered <STRONG>caught</STRONG> by this error-catching
expression.  In such a case, if <VAR>expr-2</VAR> was given, it is evaluated to get
the outcome of the entire error-catching expression; if <VAR>expr-2</VAR> was
omitted, then <VAR>E</VAR> becomes the value of the entire expression.  If <VAR>E</VAR>
is <EM>not</EM> in the list resulting from <VAR>codes</VAR>, then this expression does
not catch the error at all and it continues to be raised, possibly to be caught
by some piece of code either surrounding this expression or higher up on the
verb-call stack.

</P>
<P>
Here are some examples of the use of this kind of expression:

</P>

<PRE>
`x + 1 ! E_TYPE =&#62; 0'
</PRE>

<P>
Returns <CODE>x + 1</CODE> if <CODE>x</CODE> is an integer, returns <CODE>0</CODE> if <CODE>x</CODE> is
not an integer, and raises <CODE>E_VARNF</CODE> if <CODE>x</CODE> doesn't have a value.

</P>

<PRE>
`x.y ! E_PROPNF, E_PERM =&#62; 17'
</PRE>

<P>
Returns <CODE>x.y</CODE> if that doesn't cause an error, <CODE>17</CODE> if <CODE>x</CODE>
doesn't have a <CODE>y</CODE> property or that property isn't readable, and raises
some other kind of error (like <CODE>E_INVIND</CODE>) if <CODE>x.y</CODE> does.

</P>

<PRE>
`1 / 0 ! ANY'
</PRE>

<P>
Returns <CODE>E_DIV</CODE>.

</P>


<H3><A NAME="SEC27" HREF="ProgrammersManual_toc.html#SEC27">Parentheses and Operator Precedence</A></H3>

<P>
As shown in a few examples above, MOO allows you to use parentheses to make it
clear how you intend for complex expressions to be grouped.  For example, the
expression

</P>

<PRE>
3 * (4 + 5)
</PRE>

<P>
performs the addition of 4 and 5 before multiplying the result by 3.

</P>
<P>
If you leave out the parentheses, MOO will figure out how to group the
expression according to certain rules.  The first of these is that some
operators have higher <STRONG>precedence</STRONG> than others; operators with higher
precedence will more tightly bind to their operands than those with lower
precedence.  For example, multiplication has higher precedence than addition;
thus, if the parentheses had been left out of the expression in the previous
paragraph, MOO would have grouped it as follows:

</P>

<PRE>
(3 * 4) + 5
</PRE>

<P>
The table below gives the relative precedence of all of the MOO
operators; operators on higher lines in the table have higher precedence
and those on the same line have identical precedence:

</P>

<PRE>
!       - (without a left operand)
^
*       /       %
+       -
==      !=      &#60;       &#60;=      &#62;       &#62;=      in
&#38;&#38;      ||
... ? ... | ... (the conditional expression)
=
</PRE>

<P>
Thus, the horrendous expression

</P>

<PRE>
x = a &#60; b &#38;&#38; c &#62; d + e * f ? w in y | - q - r
</PRE>

<P>
would be grouped as follows:

</P>

<PRE>
x = (((a &#60; b) &#38;&#38; (c &#62; (d + (e * f)))) ? (w in y) | ((- q) - r))
</PRE>

<P>
It is best to keep expressions simpler than this and to use parentheses
liberally to make your meaning clear to other humans.

</P>


<H2><A NAME="SEC28" HREF="ProgrammersManual_toc.html#SEC28">MOO Language Statements</A></H2>

<P>
Statements are MOO constructs that, in contrast to expressions, perform some
useful, non-value-producing operation.  For example, there are several kinds of
statements, called `looping constructs', that repeatedly perform some set of
operations.  Fortunately, there are many fewer kinds of statements in MOO than
there are kinds of expressions.

</P>



<H3><A NAME="SEC29" HREF="ProgrammersManual_toc.html#SEC29">Errors While Executing Statements</A></H3>

<P>
Statements do not return values, but some kinds of statements can, under
certain circumstances described below, generate errors.  If such an error is
generated in a verb whose <SAMP>`d'</SAMP> (debug) bit is not set, then the error is
ignored and the statement that generated it is simply skipped; execution
proceeds with the next statement.

</P>

<BLOCKQUOTE>
<P>
<STRONG>Note:</STRONG> this error-ignoring behavior is very error prone, since it
affects <EM>all</EM> errors, including ones the programmer may not have
anticipated.  The <SAMP>`d'</SAMP> bit exists only for historical reasons; it was once
the only way for MOO programmers to catch and handle errors.  The
error-catching expression and the <CODE>try</CODE>-<CODE>except</CODE> statement are far
better ways of accomplishing the same thing.
</BLOCKQUOTE>

<P>
If the <SAMP>`d'</SAMP> bit is set, as it usually is, then the error is <STRONG>raised</STRONG>
and can be caught and handled either by code surrounding the expression in
question or by verbs higher up on the chain of calls leading to the current
verb.  If the error is not caught, then the server aborts the entire task and,
by default, prints a message to the current player.  See the descriptions of
the error-catching expression and the <CODE>try</CODE>-<CODE>except</CODE> statement for
the details of how errors can be caught, and the chapter on server assumptions
about the database for details on the handling of uncaught errors.

</P>


<H3><A NAME="SEC30" HREF="ProgrammersManual_toc.html#SEC30">Simple Statements</A></H3>

<P>
The simplest kind of statement is the <STRONG>null</STRONG> statement, consisting of just
a semicolon:

</P>

<PRE>
;
</PRE>

<P>
It doesn't do anything at all, but it does it very quickly.

</P>
<P>
The next simplest statement is also one of the most common, the expression
statement, consisting of any expression followed by a semicolon:

</P>

<PRE>
<VAR>expression</VAR>;
</PRE>

<P>
The given expression is evaluated and the resulting value is ignored.
Commonly-used kinds of expressions for such statements include
assignments and verb calls.  Of course, there's no use for such a
statement unless the evaluation of <VAR>expression</VAR> has some side-effect,
such as changing the value of some variable or property, printing some
text on someone's screen, etc.

</P>


<H3><A NAME="SEC31" HREF="ProgrammersManual_toc.html#SEC31">Statements for Testing Conditions</A></H3>

<P>
The <SAMP>`if'</SAMP> statement allows you to decide whether or not to perform some
statements based on the value of an arbitrary expression:

</P>

<PRE>
if (<VAR>expression</VAR>)
  <VAR>statements</VAR>
endif
</PRE>

<P>
<VAR>Expression</VAR> is evaluated and, if it returns a true value, the statements
are executed in order; otherwise, nothing more is done.

</P>
<P>
One frequently wants to perform one set of statements if some condition is
true and some other set of statements otherwise.  The optional <SAMP>`else'</SAMP>
phrase in an <SAMP>`if'</SAMP> statement allows you to do this:

</P>

<PRE>
if (<VAR>expression</VAR>)
  <VAR>statements-1</VAR>
else
  <VAR>statements-2</VAR>
endif
</PRE>

<P>
This statement is executed just like the previous one, except that
<VAR>statements-1</VAR> are executed if <VAR>expression</VAR> returns a true value and
<VAR>statements-2</VAR> are executed otherwise.

</P>
<P>
Sometimes, one needs to test several conditions in a kind of nested
fashion:

</P>

<PRE>
if (<VAR>expression-1</VAR>)
  <VAR>statements-1</VAR>
else
  if (<VAR>expression-2</VAR>)
    <VAR>statements-2</VAR>
  else
    if (<VAR>expression-3</VAR>)
      <VAR>statements-3</VAR>
    else
      <VAR>statements-4</VAR>
    endif
  endif
endif
</PRE>

<P>
Such code can easily become tedious to write and difficult to read.  MOO
provides a somewhat simpler notation for such cases:

</P>

<PRE>
if (<VAR>expression-1</VAR>)
  <VAR>statements-1</VAR>
elseif (<VAR>expression-2</VAR>)
  <VAR>statements-2</VAR>
elseif (<VAR>expression-3</VAR>)
  <VAR>statements-3</VAR>
else
  <VAR>statements-4</VAR>
endif
</PRE>

<P>
Note that <SAMP>`elseif'</SAMP> is written as a single word, without any spaces.  This
simpler version has the very same meaning as the original: evaluate
<VAR>expression-i</VAR> for <VAR>i</VAR> equal to 1, 2, and 3, in turn, until one of
them returns a true value; then execute the <VAR>statements-i</VAR> associated with
that expression.  If none of the <VAR>expression-i</VAR> return a true value, then
execute <VAR>statements-4</VAR>.

</P>
<P>
Any number of <SAMP>`elseif'</SAMP> phrases can appear, each having this form:

</P>

<PRE>
elseif (<VAR>expression</VAR>) <VAR>statements</VAR>
</PRE>

<P>
The complete syntax of the <SAMP>`if'</SAMP> statement, therefore, is as follows:

</P>

<PRE>
if (<VAR>expression</VAR>)
  <VAR>statements</VAR>
<VAR>zero-or-more-elseif-phrases</VAR>
<VAR>an-optional-else-phrase</VAR>
endif
</PRE>



<H3><A NAME="SEC32" HREF="ProgrammersManual_toc.html#SEC32">Statements for Looping</A></H3>

<P>
MOO provides three different kinds of looping statements, allowing you to have
a set of statements executed (1) once for each element of a given list, (2)
once for each integer or object number in a given range, and (3) over and over
until a given condition stops being true.

</P>
<P>
To perform some statements once for each element of a given list, use this
syntax:

</P>

<PRE>
for <VAR>variable</VAR> in (<VAR>expression</VAR>)
  <VAR>statements</VAR>
endfor
</PRE>

<P>
The expression is evaluated and should return a list; if it does not,
<CODE>E_TYPE</CODE> is raised.  The <VAR>statements</VAR> are then executed once for
each element of that list in turn; each time, the given <VAR>variable</VAR> is
assigned the value of the element in question.  For example, consider
the following statements:

</P>

<PRE>
odds = {1, 3, 5, 7, 9};
evens = {};
for n in (odds)
  evens = {@evens, n + 1};
endfor
</PRE>

<P>
The value of the variable <SAMP>`evens'</SAMP> after executing these statements
is the list

</P>

<PRE>
{2, 4, 6, 8, 10}
</PRE>

<P>
To perform a set of statements once for each integer or object number in a given
range, use this syntax:

</P>

<PRE>
for <VAR>variable</VAR> in [<VAR>expression-1</VAR>..<VAR>expression-2</VAR>]
  <VAR>statements</VAR>
endfor
</PRE>

<P>
The two expressions are evaluated in turn and should either both return integers
or both return object numbers; <CODE>E_TYPE</CODE> is raised otherwise.  The
<VAR>statements</VAR> are then executed once for each integer (or object number, as
appropriate) greater than or equal to the value of <VAR>expression-1</VAR> and less
than or equal to the result of <VAR>expression-2</VAR>, in increasing order.  Each
time, the given variable is assigned the integer or object number in question.
For example, consider the following statements:

</P>

<PRE>
evens = {};
for n in [1..5]
  evens = {@evens, 2 * n};
endfor
</PRE>

<P>
The value of the variable <SAMP>`evens'</SAMP> after executing these statements
is just as in the previous example: the list

</P>

<PRE>
{2, 4, 6, 8, 10}
</PRE>

<P>
The following loop over object numbers prints out the number and name of every
valid object in the database:

</P>

<PRE>
for o in [#0..max_object()]
  if (valid(o))
    notify(player, tostr(o, ": ", o.name));
  endif
endfor
</PRE>

<P>
The final kind of loop in MOO executes a set of statements repeatedly as long
as a given condition remains true:

</P>

<PRE>
while (<VAR>expression</VAR>)
  <VAR>statements</VAR>
endwhile
</PRE>

<P>
The expression is evaluated and, if it returns a true value, the
<VAR>statements</VAR> are executed; then, execution of the <SAMP>`while'</SAMP> statement
begins all over again with the evaluation of the expression.  That is,
execution alternates between evaluating the expression and executing the
statements until the expression returns a false value.  The following
example code has precisely the same effect as the loop just shown above:

</P>

<PRE>
evens = {};
n = 1;
while (n &#60;= 5)
  evens = {@evens, 2 * n};
  n = n + 1;
endwhile
</PRE>


<BLOCKQUOTE>
<P>
<EM>Fine point:</EM>  It is also possible to give a `name' to a <SAMP>`while'</SAMP>
loop, using this syntax:
 

<PRE>
while <VAR>name</VAR> (<VAR>expression</VAR>)
  <VAR>statements</VAR>
endwhile
</PRE>

<P>
which has precisely the same effect as

</P>

<PRE>
while (<VAR>name</VAR> = <VAR>expression</VAR>)
  <VAR>statements</VAR>
endwhile
</PRE>

<P>
This naming facility is only really useful in conjunction with the <SAMP>`break'</SAMP>
and <SAMP>`continue'</SAMP> statements, described in the next section.
</BLOCKQUOTE>

<P>
With each kind of loop, it is possible that the statements in the body of the
loop will never be executed at all.  For iteration over lists, this happens
when the list returned by the expression is empty.  For iteration on integers,
it happens when <VAR>expression-1</VAR> returns a larger integer than
<VAR>expression-2</VAR>.  Finally, for the <SAMP>`while'</SAMP> loop, it happens if the
expression returns a false value the very first time it is evaluated.

</P>


<H3><A NAME="SEC33" HREF="ProgrammersManual_toc.html#SEC33">Terminating One or All Iterations of a Loop</A></H3>

<P>
Sometimes, it is useful to exit a loop before it finishes all of its
iterations.  For example, if the loop is used to search for a particular kind
of element of a list, then it might make sense to stop looping as soon as the
right kind of element is found, even if there are more elements yet to see.
The <SAMP>`break'</SAMP> statement is used for this purpose; it has the form

</P>

<PRE>
break;
</PRE>

<P>
or

</P>

<PRE>
break <VAR>name</VAR>;
</PRE>

<P>
Each <SAMP>`break'</SAMP> statement indicates a specific surrounding loop; if
<VAR>name</VAR> is not given, the statement refers to the innermost one.  If it is
given, <VAR>name</VAR> must be the name appearing right after the <SAMP>`for'</SAMP> or
<SAMP>`while'</SAMP> keyword of the desired enclosing loop.  When the <SAMP>`break'</SAMP>
statement is executed, the indicated loop is immediately terminated and
executing continues just as if the loop had completed its iterations normally.

</P>
<P>
MOO also allows you to terminate just the current iteration of a loop, making
it immediately go on to the next one, if any.  The <SAMP>`continue'</SAMP> statement
does this; it has precisely the same forms as the <SAMP>`break'</SAMP> statement:

</P>

<PRE>
continue;
</PRE>

<P>
or

</P>

<PRE>
continue <VAR>name</VAR>;
</PRE>



<H3><A NAME="SEC34" HREF="ProgrammersManual_toc.html#SEC34">Returning a Value from a Verb</A></H3>

<P>
The MOO program in a verb is just a sequence of statements.  Normally, when
the verb is called, those statements are simply executed in order and then the
integer 0 is returned as the value of the verb-call expression.  Using the
<SAMP>`return'</SAMP> statement, one can change this behavior.  The <SAMP>`return'</SAMP>
statement has one of the following two forms:

</P>

<PRE>
return;
</PRE>

<P>
or

</P>

<PRE>
return <VAR>expression</VAR>;
</PRE>

<P>
When it is executed, execution of the current verb is terminated immediately
after evaluating the given <VAR>expression</VAR>, if any.  The verb-call expression
that started the execution of this verb then returns either the value of
<VAR>expression</VAR> or the integer 0, if no <VAR>expression</VAR> was provided.

</P>


<H3><A NAME="SEC35" HREF="ProgrammersManual_toc.html#SEC35">Handling Errors in Statements</A></H3>

<P>
Normally, whenever a piece of MOO code raises an error, the entire task is
aborted and a message printed to the user.  Often, such errors can be
anticipated in advance by the programmer and code written to deal with them in
a more graceful manner.  The <CODE>try</CODE>-<CODE>except</CODE> statement allows you to
do this; the syntax is as follows:

</P>

<PRE>
try
  <VAR>statements-0</VAR>
except <VAR>variable-1</VAR> (<VAR>codes-1</VAR>)
  <VAR>statements-1</VAR>
except <VAR>variable-2</VAR> (<VAR>codes-2</VAR>)
  <VAR>statements-2</VAR>
...
endtry
</PRE>

<P>
where the <VAR>variable</VAR>s may be omitted and each <VAR>codes</VAR> part is either
the keyword <CODE>ANY</CODE> or else a comma-separated list of expressions, just like
an argument list.  As in an argument list, the splicing operator (<SAMP>`@'</SAMP>)
can be used here.  There can be anywhere from 1 to 255 <CODE>except</CODE> clauses.

</P>
<P>
First, each <VAR>codes</VAR> part is evaluated, yielding a list of error codes that
should be caught if they're raised; if a <VAR>codes</VAR> is <CODE>ANY</CODE>, then it is
equivalent to the list of all possible MOO values.

</P>
<P>
Next, <VAR>statements-0</VAR> is executed; if it doesn't raise an error, then that's
all that happens for the entire <CODE>try</CODE>-<CODE>except</CODE> statement.  Otherwise,
let <VAR>E</VAR> be the error it raises.  From top to bottom, <VAR>E</VAR> is searched
for in the lists resulting from the various <VAR>codes</VAR> parts; if it isn't
found in any of them, then it continues to be raised, possibly to be caught by
some piece of code either surrounding this <CODE>try</CODE>-<CODE>except</CODE> statement
or higher up on the verb-call stack.

</P>
<P>
If <VAR>E</VAR> is found first in <VAR>codes-i</VAR>, then <VAR>variable-i</VAR> (if provided)
is assigned a value containing information about the error being raised and
<VAR>statements-i</VAR> is executed.  The value assigned to <VAR>variable-i</VAR> is a
list of four elements:

<PRE>
{<VAR>code</VAR>, <VAR>message</VAR>, <VAR>value</VAR>, <VAR>traceback</VAR>}
</PRE>

<P>
where <VAR>code</VAR> is <VAR>E</VAR>, the error being raised, <VAR>message</VAR> and
<VAR>value</VAR> are as provided by the code that raised the error, and
<VAR>traceback</VAR> is a list like that returned by the <SAMP>`callers()'</SAMP> function,
including line numbers.  The <VAR>traceback</VAR> list contains entries for every
verb from the one that raised the error through the one containing this
<CODE>try</CODE>-<CODE>except</CODE> statement.

</P>
<P>
Unless otherwise mentioned, all of the built-in errors raised by expressions,
statements, and functions provide <CODE>tostr(<VAR>code</VAR>)</CODE> as <VAR>message</VAR> and
zero as <VAR>value</VAR>.

</P>
<P>
Here's an example of the use of this kind of statement:

</P>

<PRE>
try
  result = object:(command)(@arguments);
  player:tell("=&#62; ", toliteral(result));
except v (ANY)
  tb = v[4];
  if (length(tb) == 1)
    player:tell("** Illegal command: ", v[2]);
  else
    top = tb[1];
    tb[1..1] = {};
    player:tell(top[1], ":", top[2], ", line ", top[6], ":",
                v[2]);
    for fr in (tb)
      player:tell("... called from ", fr[1], ":", fr[2],
                  ", line ", fr[6]);
    endfor
    player:tell("(End of traceback)");
  endif
endtry
</PRE>



<H3><A NAME="SEC36" HREF="ProgrammersManual_toc.html#SEC36">Cleaning Up After Errors</A></H3>

<P>
Whenever an error is raised, it is usually the case that at least some MOO code
gets skipped over and never executed.  Sometimes, it's important that a piece
of code <EM>always</EM> be executed, whether or not an error is raised.  Use the
<CODE>try</CODE>-<CODE>finally</CODE> statement for these cases; it has the following
syntax:

</P>

<PRE>
try
  <VAR>statements-1</VAR>
finally
  <VAR>statements-2</VAR>
endtry
</PRE>

<P>
First, <VAR>statements-1</VAR> is executed; if it completes without raising an
error, returning from this verb, or terminating the current iteration of a
surrounding loop (we call these possibilities <STRONG>transferring control</STRONG>), then
<VAR>statements-2</VAR> is executed and that's all that happens for the entire
<CODE>try</CODE>-<CODE>finally</CODE> statement.

</P>
<P>
Otherwise, the process of transferring control is interrupted and
<VAR>statments-2</VAR> is executed.  If <VAR>statements-2</VAR> itself completes without
transferring control, then the interrupted control transfer is resumed just
where it left off.  If <VAR>statements-2</VAR> does transfer control, then the
interrupted transfer is simply forgotten in favor of the new one.

</P>
<P>
In short, this statement ensures that <VAR>statements-2</VAR> is executed after
control leaves <VAR>statements-1</VAR> for whatever reason; it can thus be used to
make sure that some piece of cleanup code is run even if <VAR>statements-1</VAR>
doesn't simply run normally to completion.

</P>
<P>
Here's an example:

</P>

<PRE>
try
  start = time();
  object:(command)(@arguments);
finally
  end = time();
  this:charge_user_for_seconds(player, end - start);
endtry
</PRE>



<H3><A NAME="SEC37" HREF="ProgrammersManual_toc.html#SEC37">Executing Statements at a Later Time</A></H3>

<P>
It is sometimes useful to have some sequence of statements execute at a later
time, without human intervention.  For example, one might implement an object
that, when thrown into the air, eventually falls back to the ground; the
<SAMP>`throw'</SAMP> verb on that object should arrange to print a message about the
object landing on the ground, but the message shouldn't be printed until some
number of seconds have passed.

</P>
<P>
The <SAMP>`fork'</SAMP> statement is intended for just such situations and has the
following syntax:

</P>

<PRE>
fork (<VAR>expression</VAR>)
  <VAR>statements</VAR>
endfork
</PRE>

<P>
The <SAMP>`fork'</SAMP> statement first executes the expression, which must return a
integer; call that integer <VAR>n</VAR>.  It then creates a new MOO <STRONG>task</STRONG> that
will, after at least <VAR>n</VAR> seconds, execute the statements.  When the new
task begins, all variables will have the values they had at the time the
<SAMP>`fork'</SAMP> statement was executed.  The task executing the <SAMP>`fork'</SAMP>
statement immediately continues execution.  The concept of tasks is discussed
in detail in the next section.

</P>
<P>
By default, there is no limit to the number of tasks any player may fork, but
such a limit can be imposed from within the database.  See the chapter on
server assumptions about the database for details.

</P>
<P>
Occasionally, one would like to be able to kill a forked task before it even
starts; for example, some player might have caught the object that was thrown
into the air, so no message should be printed about it hitting the ground.  If
a variable name is given after the <SAMP>`fork'</SAMP> keyword, like this:

</P>

<PRE>
fork <VAR>name</VAR> (<VAR>expression</VAR>)
  <VAR>statements</VAR>
endfork
</PRE>

<P>
then that variable is assigned the <STRONG>task ID</STRONG> of the newly-created task.
The value of this variable is visible both to the task executing the fork
statement and to the statements in the newly-created task.  This ID can be
passed to the <CODE>kill_task()</CODE> function to keep the task from running and
will be the value of <CODE>task_id()</CODE> once the task begins execution.

</P>


<H2><A NAME="SEC38" HREF="ProgrammersManual_toc.html#SEC38">MOO Tasks</A></H2>

<P>
A <STRONG>task</STRONG> is an execution of a MOO program.  There are five kinds of tasks
in LambdaMOO:

</P>

<UL>
<LI>

Every time a player types a command, a task is created to execute that
command; we call these <STRONG>command tasks</STRONG>.
<LI>

Whenever a player connects or disconnects from the MOO, the server starts a
task to do whatever processing is necessary, such as printing out
<SAMP>`Munchkin has connected'</SAMP> to all of the players in the same room; these
are called <STRONG>server tasks</STRONG>.
<LI>

The <SAMP>`fork'</SAMP> statement in the programming language creates a task whose
execution is delayed for at least some given number of seconds; these are
<STRONG>forked tasks</STRONG>.
<LI>

The <CODE>suspend()</CODE> function suspends the execution of the current task.  A
snapshot is taken of whole state of the execution, and the execution will be
resumed later.  These are called <STRONG>suspended tasks</STRONG>.
<LI>

The <CODE>read()</CODE> function also suspends the execution of the current task, in
this case waiting for the player to type a line of input.  When the line is
received, the task resumes with the <CODE>read()</CODE> function returning the input
line as result.  These are called <STRONG>reading tasks</STRONG>.
</UL>

<P>
The last three kinds of tasks above are collectively known as <STRONG>queued
tasks</STRONG> or <STRONG>background tasks</STRONG>, since they may not run immediately.

</P>
<P>
To prevent a maliciously- or incorrectly-written MOO program from running
forever and monopolizing the server, limits are placed on the running time of
every task.  One limit is that no task is allowed to run longer than a certain
number of seconds; command and server tasks get five seconds each while other
tasks get only three seconds.  This limit is, in practice, rarely reached.  The
reason is that there is also a limit on the number of operations a task may
execute.

</P>
<P>
The server counts down <STRONG>ticks</STRONG> as any task executes.  Roughly speaking, it
counts one tick for every expression evaluation (other than variables and
literals), one for every <SAMP>`if'</SAMP>, <SAMP>`fork'</SAMP> or <SAMP>`return'</SAMP> statement, and
one for every iteration of a loop.  If the count gets all the way down to zero,
the task is immediately and unceremoniously aborted.  By default, command and
server tasks begin with an store of 30,000 ticks; this is enough for almost all
normal uses.  Forked, suspended, and reading tasks are allotted 15,000 ticks
each.  

</P>
<P>
These limits on seconds and ticks may be changed from within the database, as
can the behavior of the server after it aborts a task for running out; see the
chapter on server assumptions about the database for details.

</P>
<P>
Because queued tasks may exist for long periods of time before they begin
execution, there are functions to list the ones that you own and to kill them
before they execute.  These functions, among others, are discussed in the
following section.

</P>


<H2><A NAME="SEC39" HREF="ProgrammersManual_toc.html#SEC39">Built-in Functions</A></H2>

<P>
There are a large number of built-in functions available for use by MOO
programmers.  Each one is discussed in detail in this section.  The
presentation is broken up into subsections by grouping together functions with
similar or related uses.

</P>
<P>
For most functions, the expected types of the arguments are given; if the
actual arguments are not of these types, <CODE>E_TYPE</CODE> is raised.  Some
arguments can be of any type at all; in such cases, no type specification is
given for the argument.  Also, for most functions, the type of the result of
the function is given.  Some functions do not return a useful result; in such
cases, the specification <SAMP>`none'</SAMP> is used.  A few functions can potentially
return any type of value at all; in such cases, the specification <SAMP>`value'</SAMP>
is used.

</P>
<P>
Most functions take a certain fixed number of required arguments and, in some
cases, one or two optional arguments.  If a function is called with too many or
too few arguments, <CODE>E_ARGS</CODE> is raised.

</P>
<P>
Functions are always called by the program for some verb; that program is
running with the permissions of some player, usually the owner of the verb in
question (it is not always the owner, though; wizards can use
<CODE>set_task_perms()</CODE> to change the permissions `on the fly').  In the
function descriptions below, we refer to the player whose permissions are being
used as the <STRONG>programmer</STRONG>.

</P>
<P>
Many built-in functions are described below as raising <CODE>E_PERM</CODE> unless
the programmer meets certain specified criteria.  It is possible to restrict
use of any function, however, so that only wizards can use it; see the chapter
on server assumptions about the database for details.

</P>



<H3><A NAME="SEC40" HREF="ProgrammersManual_toc.html#SEC40">Object-Oriented Programming</A></H3>

<P>
One of the most important facilities in an object-oriented programming language
is ability for a child object to make use of a parent's implementation of some
operation, even when the child provides its own definition for that operation.
The <CODE>pass()</CODE> function provides this facility in MOO.

</P>
<P>
<DL>
<DT><U>Function:</U> value <B>pass</B> <I>(<VAR>arg</VAR>, ...)</I>
<DD><A NAME="IDX1"></A>
Often, it is useful for a child object to define a verb that <EM>augments</EM>
the behavior of a verb on its parent object.  For example, in the LambdaCore
database, the root object (which is an ancestor of every other object) defines
a verb called <SAMP>`description'</SAMP> that simply returns the value of
<CODE>this.description</CODE>; this verb is used by the implementation of the
<CODE>look</CODE> command.  In many cases, a programmer would like the description of
some object to include some non-constant part; for example, a sentence about
whether or not the object was `awake' or `sleeping'.  This sentence should be
added onto the end of the normal description.  The programmer would like to
have a means of calling the normal <CODE>description</CODE> verb and then appending
the sentence onto the end of that description.  The function <SAMP>`pass()'</SAMP> is
for exactly such situations.

</P>
<P>
<CODE>pass</CODE> calls the verb with the same name as the current verb but as
defined on the parent of the object that defines the current verb.  The
arguments given to <CODE>pass</CODE> are the ones given to the called verb and the
returned value of the called verb is returned from the call to <CODE>pass</CODE>.
The initial value of <CODE>this</CODE> in the called verb is the same as in the
calling verb.

</P>
<P>
Thus, in the example above, the child-object's <CODE>description</CODE> verb might
have the following implementation:

</P>

<PRE>
return pass() + "  It is " + (this.awake ? "awake." | "sleeping.");
</PRE>

<P>
That is, it calls its parent's <CODE>description</CODE> verb and then appends to the
result a sentence whose content is computed based on the value of a property on
the object.

</P>
<P>
In almost all cases, you will want to call <SAMP>`pass()'</SAMP> with the same
arguments as were given to the current verb.  This is easy to write in MOO;
just call <CODE>pass(@args)</CODE>.
</DL>

</P>


<H3><A NAME="SEC41" HREF="ProgrammersManual_toc.html#SEC41">Manipulating MOO Values</A></H3>

<P>
There are several functions for performing primitive operations on MOO values,
and they can be cleanly split into two kinds: those that do various very
general operations that apply to all types of values, and those that are
specific to one particular type.  There are so many operations concerned with
objects that we do not list them in this section but rather give them their own
section following this one.

</P>



<H4><A NAME="SEC42" HREF="ProgrammersManual_toc.html#SEC42">General Operations Applicable to all Values</A></H4>

<P>
<DL>
<DT><U>Function:</U> int <B>typeof</B> <I>(<VAR>value</VAR>)</I>
<DD><A NAME="IDX2"></A>
Takes any MOO value and returns an integer representing the type of <VAR>value</VAR>.
The result is the same as the initial value of one of these built-in variables:
<CODE>INT</CODE>, <CODE>FLOAT</CODE>, <CODE>STR</CODE>, <CODE>LIST</CODE>, <CODE>OBJ</CODE>, or <CODE>ERR</CODE>.
Thus, one usually writes code like this:

</P>

<PRE>
if (typeof(x) == LIST) ...
</PRE>

<P>
and not like this:

</P>

<PRE>
if (typeof(x) == 3) ...
</PRE>

<P>
because the former is much more readable than the latter.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> str <B>tostr</B> <I>(<VAR>value</VAR>, ...)</I>
<DD><A NAME="IDX3"></A>
Converts all of the given MOO values into strings and returns the concatenation
of the results.

</P>

<PRE>
tostr(17)                  =>   "17"
tostr(1.0/3.0)             =>   "0.333333333333333"
tostr(#17)                 =>   "#17"
tostr("foo")               =>   "foo"
tostr({1, 2})              =>   "{list}"
tostr(E_PERM)              =>   "Permission denied"
tostr("3 + 4 = ", 3 + 4)   =>   "3 + 4 = 7"
</PRE>

<P>
Note that <CODE>tostr()</CODE> does not do a good job of converting lists into
strings; all lists, including the empty list, are converted into the string
<CODE>"{list}"</CODE>.  The function <CODE>toliteral()</CODE>, below, is better for this
purpose.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> str <B>toliteral</B> <I>(<VAR>value</VAR>)</I>
<DD><A NAME="IDX4"></A>
Returns a string containing a MOO literal expression that, when evaluated,
would be equal to <VAR>value</VAR>.

</P>

<PRE>
toliteral(17)         =>   "17"
toliteral(1.0/3.0)    =>   "0.333333333333333"
toliteral(#17)        =>   "#17"
toliteral("foo")      =>   "\"foo\""
toliteral({1, 2})     =>   "{1, 2}"
toliteral(E_PERM)     =>   "E_PERM"
</PRE>

</DL>

<P>
<DL>
<DT><U>Function:</U> int <B>toint</B> <I>(<VAR>value</VAR>)</I>
<DD><A NAME="IDX5"></A>
<DT><U>Function:</U> int <B>tonum</B> <I>(<VAR>value</VAR>)</I>
<DD><A NAME="IDX6"></A>
Converts the given MOO value into an integer and returns that integer.
Floating-point numbers are rounded toward zero, truncating their fractional
parts.  Object numbers are converted into the equivalent integers.  Strings are
parsed as the decimal encoding of a real number which is then converted to an
integer.  Errors are converted into integers obeying the same ordering (with
respect to <CODE>&#60;=</CODE> as the errors themselves.  <CODE>Toint()</CODE> raises
<CODE>E_TYPE</CODE> if <VAR>value</VAR> is a list.  If <VAR>value</VAR> is a string but the
string does not contain a syntactically-correct number, then <CODE>toint()</CODE>
returns 0.

</P>

<PRE>
toint(34.7)        =>   34
toint(-34.7)       =>   -34
toint(#34)         =>   34
toint("34")        =>   34
toint("34.7")      =>   34
toint(" - 34  ")   =>   -34
toint(E_TYPE)      =>   1
</PRE>

</DL>

<P>
<DL>
<DT><U>Function:</U> obj <B>toobj</B> <I>(<VAR>value</VAR>)</I>
<DD><A NAME="IDX7"></A>
Converts the given MOO value into an object number and returns that object
number.  The conversions are very similar to those for <CODE>toint()</CODE> except
that for strings, the number <EM>may</EM> be preceded by <SAMP>`#'</SAMP>.

</P>

<PRE>
toobj("34")       =>   #34
toobj("#34")      =>   #34
toobj("foo")      =>   #0
toobj({1, 2})     error-->   E_TYPE
</PRE>

</DL>

<P>
<DL>
<DT><U>Function:</U> float <B>tofloat</B> <I>(<VAR>value</VAR>)</I>
<DD><A NAME="IDX8"></A>
Converts the given MOO value into a floating-point number and returns that
number.  Integers and object numbers are converted into the corresponding
integral floating-point numbers.  Strings are parsed as the decimal encoding of
a real number which is then represented as closely as possible as a
floating-point number.  Errors are first converted to integers as in
<CODE>toint()</CODE> and then converted as integers are.  <CODE>Tofloat()</CODE> raises
<CODE>E_TYPE</CODE> if <VAR>value</VAR> is a list.  If <VAR>value</VAR> is a string but the
string does not contain a syntactically-correct number, then <CODE>tofloat()</CODE>
returns 0.

</P>

<PRE>
tofloat(34)          =>   34.0
tofloat(#34)         =>   34.0
tofloat("34")        =>   34.0
tofloat("34.7")      =>   34.7
tofloat(E_TYPE)      =>   1.0
</PRE>

</DL>

<P>
<DL>
<DT><U>Function:</U> int <B>equal</B> <I>(<VAR>value1</VAR>, <VAR>value2</VAR>)</I>
<DD><A NAME="IDX9"></A>
Returns true if <VAR>value1</VAR> is completely indistinguishable from <VAR>value2</VAR>.
This is much the same operation as "<CODE><VAR>value1</VAR> == <VAR>value2</VAR></CODE>"
except that, unlike <CODE>==</CODE>, the <CODE>equal()</CODE> function does not treat
upper- and lower-case characters in strings as equal.

</P>

<PRE>
"Foo" == "foo"         =>   1
equal("Foo", "foo")    =>   0
equal("Foo", "Foo")    =>   1
</PRE>

</DL>

<P>
<DL>
<DT><U>Function:</U> int <B>value_bytes</B> <I>(<VAR>value</VAR>)</I>
<DD><A NAME="IDX10"></A>
Returns the number of bytes of the server's memory required to store the given
<VAR>value</VAR>.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> str <B>value_hash</B> <I>(<VAR>value</VAR>)</I>
<DD><A NAME="IDX11"></A>
Returns the same string as <CODE>string_hash(toliteral(<VAR>value</VAR>))</CODE>; see the
description of <CODE>string_hash()</CODE> for details.
</DL>

</P>


<H4><A NAME="SEC43" HREF="ProgrammersManual_toc.html#SEC43">Operations on Numbers</A></H4>

<P>
<DL>
<DT><U>Function:</U> int <B>random</B> <I>([int <VAR>mod</VAR>])</I>
<DD><A NAME="IDX12"></A>
<VAR>mod</VAR> must be a positive integer; otherwise, <CODE>E_INVARG</CODE> is raised.  An
integer is chosen randomly from the range <CODE>[1..<VAR>mod</VAR>]</CODE> and returned.
If <VAR>mod</VAR> is not provided, it defaults to the largest MOO integer,
2147483647.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> num <B>min</B> <I>(num <VAR>x</VAR>, ...)</I>
<DD><A NAME="IDX13"></A>
<DT><U>Function:</U> num <B>max</B> <I>(num <VAR>x</VAR>, ...)</I>
<DD><A NAME="IDX14"></A>
These two functions return the smallest or largest of their arguments,
respectively.  All of the arguments must be numbers of the same kind (i.e.,
either integer or floating-point); otherwise <CODE>E_TYPE</CODE> is raised.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> num <B>abs</B> <I>(num <VAR>x</VAR>)</I>
<DD><A NAME="IDX15"></A>
Returns the absolute value of <VAR>x</VAR>.  If <VAR>x</VAR> is negative, then the result
is <CODE>-<VAR>x</VAR></CODE>; otherwise, the result is <VAR>x</VAR>.  The number <VAR>x</VAR> can
be either integer or floating-point; the result is of the same kind.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> str <B>floatstr(float</B> <I><VAR>x</VAR>, int <VAR>precision</VAR> [, <VAR>scientific</VAR>])</I>
<DD><A NAME="IDX16"></A>
Converts <VAR>x</VAR> into a string with more control than provided by either
<CODE>tostr()</CODE> or <CODE>toliteral()</CODE>.  <VAR>Precision</VAR> is the number of digits
to appear to the right of the decimal point, capped at 4 more than the maximum
available precision, a total of 19 on most machines; this makes it possible to
avoid rounding errors if the resulting string is subsequently read back as a
floating-point value.  If <VAR>scientific</VAR> is false or not provided, the result
is a string in the form <CODE>"MMMMMMM.DDDDDD"</CODE>, preceded by a minus sign if
and only if <VAR>x</VAR> is negative.  If <VAR>scientific</VAR> is provided and true, the
result is a string in the form <CODE>"M.DDDDDDe+EEE"</CODE>, again preceded by a
minus sign if and only if <VAR>x</VAR> is negative.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> float <B>sqrt</B> <I>(float <VAR>x</VAR>)</I>
<DD><A NAME="IDX17"></A>
Returns the square root of <VAR>x</VAR>.  Raises <CODE>E_INVARG</CODE> if <VAR>x</VAR> is
negative.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> float <B>sin</B> <I>(float <VAR>x</VAR>)</I>
<DD><A NAME="IDX18"></A>
<DT><U>Function:</U> float <B>cos</B> <I>(float <VAR>x</VAR>)</I>
<DD><A NAME="IDX19"></A>
<DT><U>Function:</U> float <B>tan</B> <I>(float <VAR>x</VAR>)</I>
<DD><A NAME="IDX20"></A>
Returns the sine, cosine, or tangent of <VAR>x</VAR>, respectively.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> float <B>asin</B> <I>(float <VAR>x</VAR>)</I>
<DD><A NAME="IDX21"></A>
<DT><U>Function:</U> float <B>acos</B> <I>(float <VAR>x</VAR>)</I>
<DD><A NAME="IDX22"></A>
Returns the arc-sine or arc-cosine (inverse sine or cosine) of <VAR>x</VAR>, in the
range <CODE>[-pi/2..pi/2]</CODE> or <CODE>[0..pi]</CODE>, respectively.  Raises
<CODE>E_INVARG</CODE> if <VAR>x</VAR> is outside the range <CODE>[-1.0..1.0]</CODE>.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> float <B>atan</B> <I>(float <VAR>y</VAR> [, float <VAR>x</VAR>])</I>
<DD><A NAME="IDX23"></A>
Returns the arc-tangent (inverse tangent) of <VAR>y</VAR> in the range
<CODE>[-pi/2..pi/2]</CODE> if <VAR>x</VAR> is not provided, or of <CODE><VAR>y</VAR>/<VAR>x</VAR></CODE>
in the range <CODE>[-pi..pi]</CODE> if <VAR>x</VAR> is provided.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> float <B>sinh</B> <I>(float <VAR>x</VAR>)</I>
<DD><A NAME="IDX24"></A>
<DT><U>Function:</U> float <B>cosh</B> <I>(float <VAR>x</VAR>)</I>
<DD><A NAME="IDX25"></A>
<DT><U>Function:</U> float <B>tanh</B> <I>(float <VAR>x</VAR>)</I>
<DD><A NAME="IDX26"></A>
Returns the hyperbolic sine, cosine, or tangent of <VAR>x</VAR>, respectively.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> float <B>exp</B> <I>(float <VAR>x</VAR>)</I>
<DD><A NAME="IDX27"></A>
Returns <VAR>e</VAR> raised to the power of <VAR>x</VAR>.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> float <B>log</B> <I>(float <VAR>x</VAR>)</I>
<DD><A NAME="IDX28"></A>
<DT><U>Function:</U> float <B>log10</B> <I>(float <VAR>x</VAR>)</I>
<DD><A NAME="IDX29"></A>
Returns the natural or base 10 logarithm of <VAR>x</VAR>.  Raises <CODE>E_INVARG</CODE> if
<VAR>x</VAR> is not positive.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> float <B>ceil</B> <I>(float <VAR>x</VAR>)</I>
<DD><A NAME="IDX30"></A>
Returns the smallest integer not less than <VAR>x</VAR>, as a floating-point number.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> float <B>floor</B> <I>(float <VAR>x</VAR>)</I>
<DD><A NAME="IDX31"></A>
Returns the largest integer not greater than <VAR>x</VAR>, as a floating-point
number.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> float <B>trunc</B> <I>(float <VAR>x</VAR>)</I>
<DD><A NAME="IDX32"></A>
Returns the integer obtained by truncating <VAR>x</VAR> at the decimal point, as a
floating-point number.  For negative <VAR>x</VAR>, this is equivalent to
<CODE>ceil()</CODE>; otherwise it is equivalent to <CODE>floor()</CODE>.
</DL>

</P>


<H4><A NAME="SEC44" HREF="ProgrammersManual_toc.html#SEC44">Operations on Strings</A></H4>

<P>
<DL>
<DT><U>Function:</U> int <B>length</B> <I>(str <VAR>string</VAR>)</I>
<DD><A NAME="IDX33"></A>
Returns the number of characters in <VAR>string</VAR>.  It is also permissible to
pass a list to <CODE>length()</CODE>; see the description in the next section.

</P>

<PRE>
length("foo")   =>   3
length("")      =>   0
</PRE>

</DL>

<P>
<DL>
<DT><U>Function:</U> str <B>strsub</B> <I>(str <VAR>subject</VAR>, str <VAR>what</VAR>, str <VAR>with</VAR> [, <VAR>case-matters</VAR>])</I>
<DD><A NAME="IDX34"></A>
Replaces all occurrences in <VAR>subject</VAR> of <VAR>what</VAR> with <VAR>with</VAR>,
performing string substitution.  The occurrences are found from left to right
and all substitutions happen simultaneously.  By default, occurrences of
<VAR>what</VAR> are searched for while ignoring the upper/lower case distinction.
If <VAR>case-matters</VAR> is provided and true, then case is treated as significant
in all comparisons.

</P>

<PRE>
strsub("%n is a fink.", "%n", "Fred")   =>   "Fred is a fink."
strsub("foobar", "OB", "b")             =>   "fobar"
strsub("foobar", "OB", "b", 1)          =>   "foobar"
</PRE>

</DL>

<P>
<DL>
<DT><U>Function:</U> int <B>index</B> <I>(str <VAR>str1</VAR>, str <VAR>str2</VAR> [, <VAR>case-matters</VAR>])</I>
<DD><A NAME="IDX35"></A>
<DT><U>Function:</U> int <B>rindex</B> <I>(str <VAR>str1</VAR>, str <VAR>str2</VAR> [, <VAR>case-matters</VAR>])</I>
<DD><A NAME="IDX36"></A>
The function <CODE>index()</CODE> (<CODE>rindex()</CODE>) returns the index of the first
character of the first (last) occurrence of <VAR>str2</VAR> in <VAR>str1</VAR>, or zero
if <VAR>str2</VAR> does not occur in <VAR>str1</VAR> at all.  By default the search for
an occurrence of <VAR>str2</VAR> is done while ignoring the upper/lower case
distinction.  If <VAR>case-matters</VAR> is provided and true, then case is treated
as significant in all comparisons.

</P>

<PRE>
index("foobar", "o")        =>   2
rindex("foobar", "o")       =>   3
index("foobar", "x")        =>   0
index("foobar", "oba")      =>   3
index("Foobar", "foo", 1)   =>   0
</PRE>

</DL>

<P>
<DL>
<DT><U>Function:</U> int <B>strcmp</B> <I>(str <VAR>str1</VAR>, str <VAR>str2</VAR>)</I>
<DD><A NAME="IDX37"></A>
Performs a case-sensitive comparison of the two argument strings.  If
<VAR>str1</VAR> is lexicographically less than <VAR>str2</VAR>, the
<CODE>strcmp()</CODE> returns a negative integer.  If the two strings are
identical, <CODE>strcmp()</CODE> returns zero.  Otherwise, <CODE>strcmp()</CODE>
returns a positive integer.  The ASCII character ordering is used for the
comparison.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> list <B>decode_binary</B> <I>(str <VAR>bin-string</VAR> [, <VAR>fully</VAR>])</I>
<DD><A NAME="IDX38"></A>
Returns a list of strings and/or integers representing the bytes in the binary
string <VAR>bin_string</VAR> in order.  If <VAR>fully</VAR> is false or omitted, the list
contains an integer only for each non-printing, non-space byte; all other
characters are grouped into the longest possible contiguous substrings.  If
<VAR>fully</VAR> is provided and true, the list contains only integers, one for each
byte represented in <VAR>bin_string</VAR>.  Raises <CODE>E_INVARG</CODE> if
<VAR>bin_string</VAR> is not a properly-formed binary string.  (See the early
section on MOO value types for a full description of binary strings.)

</P>

<PRE>
decode_binary("foo")               =>   {"foo"}
decode_binary("~~foo")             =>   {"~foo"}
decode_binary("foo~0D~0A")         =>   {"foo", 13, 10}
decode_binary("foo~0Abar~0Abaz")   =>   {"foo", 10, "bar", 10, "baz"}
decode_binary("foo~0D~0A", 1)      =>   {102, 111, 111, 13, 10}
</PRE>

</DL>

<P>
<DL>
<DT><U>Function:</U> str <B>encode_binary</B> <I>(<VAR>arg</VAR>, ...)</I>
<DD><A NAME="IDX39"></A>
Each argument must be an integer between 0 and 255, a string, or a list
containing only legal arguments for this function.  This function translates
each integer and string in turn into its binary string equivalent, returning the
concatenation of all these substrings into a single binary string.  (See the
early section on MOO value types for a full description of binary strings.)

</P>

<PRE>
encode_binary("~foo")                     =>   "~7Efoo"
encode_binary({"foo", 10}, {"bar", 13})   =>   "foo~0Abar~0D"
encode_binary("foo", 10, "bar", 13)       =>   "foo~0Abar~0D"
</PRE>

</DL>

<P>
<DL>
<DT><U>Function:</U> list <B>match</B> <I>(str <VAR>subject</VAR>, str <VAR>pattern</VAR> [, <VAR>case-matters</VAR>])</I>
<DD><A NAME="IDX40"></A>
<DT><U>Function:</U> list <B>rmatch</B> <I>(str <VAR>subject</VAR>, str <VAR>pattern</VAR> [, <VAR>case-matters</VAR>])</I>
<DD><A NAME="IDX41"></A>
The function <CODE>match()</CODE> (<CODE>rmatch()</CODE>) searches for the first (last)
occurrence of the regular expression <VAR>pattern</VAR> in the string <VAR>subject</VAR>.
If <VAR>pattern</VAR> is syntactically malformed, then <CODE>E_INVARG</CODE> is raised.
The process of matching can in some cases consume a great deal of memory in the
server; should this memory consumption become excessive, then the matching
process is aborted and <CODE>E_QUOTA</CODE> is raised.

</P>
<P>
If no match is found, the empty list is returned; otherwise, these functions
return a list containing information about the match (see below).  By default,
the search ignores upper-/lower-case distinctions.  If <VAR>case-matters</VAR> is
provided and true, then case is treated as significant in all comparisons.

</P>
<P>
The list that <CODE>match()</CODE> (<CODE>rmatch()</CODE>) returns contains the details
about the match made.  The list is in the form:

</P>

<PRE>
{<VAR>start</VAR>, <VAR>end</VAR>, <VAR>replacements</VAR>, <VAR>subject</VAR>}
</PRE>

<P>
where <VAR>start</VAR> is the index in <VAR>subject</VAR> of the beginning of the match,
<VAR>end</VAR> is the index of the end of the match, <VAR>replacements</VAR> is a list
described below, and <VAR>subject</VAR> is the same string that was given as the
first argument to the <CODE>match()</CODE> or <CODE>rmatch()</CODE>.

</P>
<P>
The <VAR>replacements</VAR> list is always nine items long, each item itself being a
list of two integers, the start and end indices in <VAR>string</VAR> matched by some
parenthesized sub-pattern of <VAR>pattern</VAR>.  The first item in
<VAR>replacements</VAR> carries the indices for the first parenthesized sub-pattern,
the second item carries those for the second sub-pattern, and so on.  If there
are fewer than nine parenthesized sub-patterns in <VAR>pattern</VAR>, or if some
sub-pattern was not used in the match, then the corresponding item in
<VAR>replacements</VAR> is the list {0, -1}.  See the discussion of <SAMP>`%)'</SAMP>,
below, for more information on parenthesized sub-patterns.

</P>

<PRE>
match("foo", "^f*o$")        =>  {}
match("foo", "^fo*$")        =>  {1, 3, {{0, -1}, ...}, "foo"}
match("foobar", "o*b")       =>  {2, 4, {{0, -1}, ...}, "foobar"}
rmatch("foobar", "o*b")      =>  {4, 4, {{0, -1}, ...}, "foobar"}
match("foobar", "f%(o*%)b")
        =>  {1, 4, {{2, 3}, {0, -1}, ...}, "foobar"}
</PRE>

<P>
<STRONG>Regular expression</STRONG> matching allows you to test whether a string fits into
a specific syntactic shape.  You can also search a string for a substring that
fits a pattern.

</P>
<P>
A regular expression describes a set of strings.  The simplest case is one that
describes a particular string; for example, the string <SAMP>`foo'</SAMP> when regarded
as a regular expression matches <SAMP>`foo'</SAMP> and nothing else.  Nontrivial
regular expressions use certain special constructs so that they can match more
than one string.  For example, the regular expression <SAMP>`foo%|bar'</SAMP> matches
either the string <SAMP>`foo'</SAMP> or the string <SAMP>`bar'</SAMP>; the regular expression
<SAMP>`c[ad]*r'</SAMP> matches any of the strings <SAMP>`cr'</SAMP>, <SAMP>`car'</SAMP>, <SAMP>`cdr'</SAMP>,
<SAMP>`caar'</SAMP>, <SAMP>`cadddar'</SAMP> and all other such strings with any number of
<SAMP>`a'</SAMP>'s and <SAMP>`d'</SAMP>'s.

</P>
<P>
Regular expressions have a syntax in which a few characters are special
constructs and the rest are <STRONG>ordinary</STRONG>.  An ordinary character is a simple
regular expression that matches that character and nothing else.  The special
characters are <SAMP>`$'</SAMP>, <SAMP>`^'</SAMP>, <SAMP>`.'</SAMP>, <SAMP>`*'</SAMP>, <SAMP>`+'</SAMP>, <SAMP>`?'</SAMP>,
<SAMP>`['</SAMP>, <SAMP>`]'</SAMP> and <SAMP>`%'</SAMP>.  Any other character appearing in a regular
expression is ordinary, unless a <SAMP>`%'</SAMP> precedes it.

</P>
<P>
For example, <SAMP>`f'</SAMP> is not a special character, so it is ordinary, and
therefore <SAMP>`f'</SAMP> is a regular expression that matches the string <SAMP>`f'</SAMP> and
no other string.  (It does <EM>not</EM>, for example, match the string
<SAMP>`ff'</SAMP>.)  Likewise, <SAMP>`o'</SAMP> is a regular expression that matches only
<SAMP>`o'</SAMP>.

</P>
<P>
Any two regular expressions <VAR>a</VAR> and <VAR>b</VAR> can be concatenated.  The
result is a regular expression which matches a string if <VAR>a</VAR> matches some
amount of the beginning of that string and <VAR>b</VAR> matches the rest of the
string.

</P>
<P>
As a simple example, we can concatenate the regular expressions <SAMP>`f'</SAMP> and
<SAMP>`o'</SAMP> to get the regular expression <SAMP>`fo'</SAMP>, which matches only the string
<SAMP>`fo'</SAMP>.  Still trivial.

</P>
<P>
The following are the characters and character sequences that have special
meaning within regular expressions.  Any character not mentioned here is not
special; it stands for exactly itself for the purposes of searching and
matching.

</P>
<DL COMPACT>

<DT><SAMP>`.'</SAMP>
<DD>
is a special character that matches any single character.  Using concatenation,
we can make regular expressions like <SAMP>`a.b'</SAMP>, which matches any
three-character string that begins with <SAMP>`a'</SAMP> and ends with <SAMP>`b'</SAMP>.

<DT><SAMP>`*'</SAMP>
<DD>
is not a construct by itself; it is a suffix that means that the preceding
regular expression is to be repeated as many times as possible.  In <SAMP>`fo*'</SAMP>,
the <SAMP>`*'</SAMP> applies to the <SAMP>`o'</SAMP>, so <SAMP>`fo*'</SAMP> matches <SAMP>`f'</SAMP> followed
by any number of <SAMP>`o'</SAMP>'s.

The case of zero <SAMP>`o'</SAMP>'s is allowed: <SAMP>`fo*'</SAMP> does match <SAMP>`f'</SAMP>.

<SAMP>`*'</SAMP> always applies to the <EM>smallest</EM> possible preceding expression.
Thus, <SAMP>`fo*'</SAMP> has a repeating <SAMP>`o'</SAMP>, not a repeating <SAMP>`fo'</SAMP>.

The matcher processes a <SAMP>`*'</SAMP> construct by matching, immediately, as many
repetitions as can be found.  Then it continues with the rest of the pattern.
If that fails, it backtracks, discarding some of the matches of the <SAMP>`*'</SAMP>'d
construct in case that makes it possible to match the rest of the pattern.  For
example, matching <SAMP>`c[ad]*ar'</SAMP> against the string <SAMP>`caddaar'</SAMP>, the
<SAMP>`[ad]*'</SAMP> first matches <SAMP>`addaa'</SAMP>, but this does not allow the next
<SAMP>`a'</SAMP> in the pattern to match.  So the last of the matches of <SAMP>`[ad]'</SAMP> is
undone and the following <SAMP>`a'</SAMP> is tried again.  Now it succeeds.

<DT><SAMP>`+'</SAMP>
<DD>
<SAMP>`+'</SAMP> is like <SAMP>`*'</SAMP> except that at least one match for the preceding
pattern is required for <SAMP>`+'</SAMP>.  Thus, <SAMP>`c[ad]+r'</SAMP> does not match
<SAMP>`cr'</SAMP> but does match anything else that <SAMP>`c[ad]*r'</SAMP> would match.

<DT><SAMP>`?'</SAMP>
<DD>
<SAMP>`?'</SAMP> is like <SAMP>`*'</SAMP> except that it allows either zero or one match for
the preceding pattern.  Thus, <SAMP>`c[ad]?r'</SAMP> matches <SAMP>`cr'</SAMP> or <SAMP>`car'</SAMP> or
<SAMP>`cdr'</SAMP>, and nothing else.

<DT><SAMP>`[ ... ]'</SAMP>
<DD>
<SAMP>`['</SAMP> begins a <STRONG>character set</STRONG>, which is terminated by a <SAMP>`]'</SAMP>.  In
the simplest case, the characters between the two brackets form the set.  Thus,
<SAMP>`[ad]'</SAMP> matches either <SAMP>`a'</SAMP> or <SAMP>`d'</SAMP>, and <SAMP>`[ad]*'</SAMP> matches any
string of <SAMP>`a'</SAMP>'s and <SAMP>`d'</SAMP>'s (including the empty string), from which it
follows that <SAMP>`c[ad]*r'</SAMP> matches <SAMP>`car'</SAMP>, etc.

Character ranges can also be included in a character set, by writing two
characters with a <SAMP>`-'</SAMP> between them.  Thus, <SAMP>`[a-z]'</SAMP> matches any
lower-case letter.  Ranges may be intermixed freely with individual characters,
as in <SAMP>`[a-z$%.]'</SAMP>, which matches any lower case letter or <SAMP>`$'</SAMP>,
<SAMP>`%'</SAMP> or period.

Note that the usual special characters are not special any more inside a
character set.  A completely different set of special characters exists inside
character sets: <SAMP>`]'</SAMP>, <SAMP>`-'</SAMP> and <SAMP>`^'</SAMP>.

To include a <SAMP>`]'</SAMP> in a character set, you must make it the first character.
For example, <SAMP>`[]a]'</SAMP> matches <SAMP>`]'</SAMP> or <SAMP>`a'</SAMP>.  To include a <SAMP>`-'</SAMP>,
you must use it in a context where it cannot possibly indicate a range: that
is, as the first character, or immediately after a range.

<DT><SAMP>`[^ ... ]'</SAMP>
<DD>
<SAMP>`[^'</SAMP> begins a <STRONG>complement character set</STRONG>, which matches any character
except the ones specified.  Thus, <SAMP>`[^a-z0-9A-Z]'</SAMP> matches all characters
<EM>except</EM> letters and digits.

<SAMP>`^'</SAMP> is not special in a character set unless it is the first character.
The character following the <SAMP>`^'</SAMP> is treated as if it were first (it may be
a <SAMP>`-'</SAMP> or a <SAMP>`]'</SAMP>).

<DT><SAMP>`^'</SAMP>
<DD>
is a special character that matches the empty string -- but only if at the
beginning of the string being matched.  Otherwise it fails to match anything.
Thus, <SAMP>`^foo'</SAMP> matches a <SAMP>`foo'</SAMP> which occurs at the beginning of the
string.

<DT><SAMP>`$'</SAMP>
<DD>
is similar to <SAMP>`^'</SAMP> but matches only at the <EM>end</EM> of the string.  Thus,
<SAMP>`xx*$'</SAMP> matches a string of one or more <SAMP>`x'</SAMP>'s at the end of the
string.

<DT><SAMP>`%'</SAMP>
<DD>
has two functions: it quotes the above special characters (including <SAMP>`%'</SAMP>),
and it introduces additional special constructs.

Because <SAMP>`%'</SAMP> quotes special characters, <SAMP>`%$'</SAMP> is a regular expression
that matches only <SAMP>`$'</SAMP>, and <SAMP>`%['</SAMP> is a regular expression that matches
only <SAMP>`['</SAMP>, and so on.

For the most part, <SAMP>`%'</SAMP> followed by any character matches only that
character.  However, there are several exceptions: characters that, when
preceded by <SAMP>`%'</SAMP>, are special constructs.  Such characters are always
ordinary when encountered on their own.

No new special characters will ever be defined.  All extensions to the regular
expression syntax are made by defining new two-character constructs that begin
with <SAMP>`%'</SAMP>.

<DT><SAMP>`%|'</SAMP>
<DD>
specifies an alternative.  Two regular expressions <VAR>a</VAR> and <VAR>b</VAR> with
<SAMP>`%|'</SAMP> in between form an expression that matches anything that either
<VAR>a</VAR> or <VAR>b</VAR> will match.

Thus, <SAMP>`foo%|bar'</SAMP> matches either <SAMP>`foo'</SAMP> or <SAMP>`bar'</SAMP> but no other
string.

<SAMP>`%|'</SAMP> applies to the largest possible surrounding expressions.  Only a
surrounding <SAMP>`%( ... %)'</SAMP> grouping can limit the grouping power of
<SAMP>`%|'</SAMP>.

Full backtracking capability exists for when multiple <SAMP>`%|'</SAMP>'s are used.

<DT><SAMP>`%( ... %)'</SAMP>
<DD>
is a grouping construct that serves three purposes:


<OL>
<LI>

To enclose a set of <SAMP>`%|'</SAMP> alternatives for other operations.  Thus,
<SAMP>`%(foo%|bar%)x'</SAMP> matches either <SAMP>`foox'</SAMP> or <SAMP>`barx'</SAMP>.

<LI>

To enclose a complicated expression for a following <SAMP>`*'</SAMP>, <SAMP>`+'</SAMP>, or
<SAMP>`?'</SAMP> to operate on.  Thus, <SAMP>`ba%(na%)*'</SAMP> matches <SAMP>`bananana'</SAMP>, etc.,
with any number of <SAMP>`na'</SAMP>'s, including none.

<LI>

To mark a matched substring for future reference.
</OL>

This last application is not a consequence of the idea of a parenthetical
grouping; it is a separate feature that happens to be assigned as a second
meaning to the same <SAMP>`%( ... %)'</SAMP> construct because there is no conflict
in practice between the two meanings.  Here is an explanation of this feature:

<DT><SAMP>`%<VAR>digit</VAR>'</SAMP>
<DD>
After the end of a <SAMP>`%( ... %)'</SAMP> construct, the matcher remembers the
beginning and end of the text matched by that construct.  Then, later on in the
regular expression, you can use <SAMP>`%'</SAMP> followed by <VAR>digit</VAR> to mean
"match the same text matched by the <VAR>digit</VAR>'th <SAMP>`%( ... %)'</SAMP>
construct in the pattern."  The <SAMP>`%( ... %)'</SAMP> constructs are numbered
in the order that their <SAMP>`%('</SAMP>'s appear in the pattern.

The strings matching the first nine <SAMP>`%( ... %)'</SAMP> constructs appearing
in a regular expression are assigned numbers 1 through 9 in order of their
beginnings.  <SAMP>`%1'</SAMP> through <SAMP>`%9'</SAMP> may be used to refer to the text
matched by the corresponding <SAMP>`%( ... %)'</SAMP> construct.

For example, <SAMP>`%(.*%)%1'</SAMP> matches any string that is composed of two
identical halves.  The <SAMP>`%(.*%)'</SAMP> matches the first half, which may be
anything, but the <SAMP>`%1'</SAMP> that follows must match the same exact text.

<DT><SAMP>`%b'</SAMP>
<DD>
matches the empty string, but only if it is at the beginning or
end of a word.  Thus, <SAMP>`%bfoo%b'</SAMP> matches any occurrence of
<SAMP>`foo'</SAMP> as a separate word.  <SAMP>`%bball%(s%|%)%b'</SAMP> matches
<SAMP>`ball'</SAMP> or <SAMP>`balls'</SAMP> as a separate word.

For the purposes of this construct and the five that follow, a word is defined
to be a sequence of letters and/or digits.

<DT><SAMP>`%B'</SAMP>
<DD>
matches the empty string, provided it is <EM>not</EM> at the beginning or
end of a word.

<DT><SAMP>`%&#60;'</SAMP>
<DD>
matches the empty string, but only if it is at the beginning
of a word.

<DT><SAMP>`%&#62;'</SAMP>
<DD>
matches the empty string, but only if it is at the end of a word.

<DT><SAMP>`%w'</SAMP>
<DD>
matches any word-constituent character (i.e., any letter or digit).

<DT><SAMP>`%W'</SAMP>
<DD>
matches any character that is not a word constituent.
</DL>
</DL>

<P>
<DL>
<DT><U>Function:</U> str <B>substitute</B> <I>(str <VAR>template</VAR>, list <VAR>subs</VAR>)</I>
<DD><A NAME="IDX42"></A>
Performs a standard set of substitutions on the string <VAR>template</VAR>, using
the information contained in <VAR>subs</VAR>, returning the resulting, transformed
<VAR>template</VAR>.  <VAR>Subs</VAR> should be a list like those returned by
<CODE>match()</CODE> or <CODE>rmatch()</CODE> when the match succeeds; otherwise,
<CODE>E_INVARG</CODE> is raised.

</P>
<P>
In <VAR>template</VAR>, the strings <SAMP>`%1'</SAMP> through <SAMP>`%9'</SAMP> will be replaced by
the text matched by the first through ninth parenthesized sub-patterns when
<CODE>match()</CODE> or <CODE>rmatch()</CODE> was called.  The string <SAMP>`%0'</SAMP> in
<VAR>template</VAR> will be replaced by the text matched by the pattern as a whole
when <CODE>match()</CODE> or <CODE>rmatch()</CODE> was called.  The string <SAMP>`%%'</SAMP> will
be replaced by a single <SAMP>`%'</SAMP> sign.  If <SAMP>`%'</SAMP> appears in <VAR>template</VAR>
followed by any other character, <CODE>E_INVARG</CODE> will be raised.

</P>

<PRE>
subs = match("*** Welcome to LambdaMOO!!!", "%(%w*%) to %(%w*%)");
substitute("I thank you for your %1 here in %2.", subs)
        =>   "I thank you for your Welcome here in LambdaMOO."
</PRE>

</DL>

<P>
<DL>
<DT><U>Function:</U> str <B>crypt</B> <I>(str <VAR>text</VAR> [, str <VAR>salt</VAR>])</I>
<DD><A NAME="IDX43"></A>
Encrypts the given <VAR>text</VAR> using the standard UNIX encryption method.  If
provided, <VAR>salt</VAR> should be a string at least two characters long, the first
two characters of which will be used as the extra encryption "salt" in the
algorithm.  If <VAR>salt</VAR> is not provided, a random pair of characters is used.
In any case, the salt used is also returned as the first two characters of the
resulting encrypted string.

</P>
<P>
Aside from the possibly-random selection of the salt, the encryption algorithm
is entirely deterministic.  In particular, you can test whether or not a given
string is the same as the one used to produce a given piece of encrypted text;
simply extract the first two characters of the encrypted text and pass the
candidate string and those two characters to <CODE>crypt()</CODE>.  If the result is
identical to the given encrypted text, then you've got a match.

</P>

<PRE>
crypt("foobar")         =>   "J3fSFQfgkp26w"
crypt("foobar", "J3")   =>   "J3fSFQfgkp26w"
crypt("mumble", "J3")   =>   "J3D0.dh.jjmWQ"
crypt("foobar", "J4")   =>   "J4AcPxOJ4ncq2"
</PRE>

</DL>

<P>
<DL>
<DT><U>Function:</U> str <B>string_hash</B> <I>(str <VAR>text</VAR>)</I>
<DD><A NAME="IDX44"></A>
<DT><U>Function:</U> str <B>binary_hash</B> <I>(str <VAR>bin-string</VAR>)</I>
<DD><A NAME="IDX45"></A>
Returns a 32-character hexadecimal string encoding the result of applying the
MD5 cryptographically secure hash function to the contents of the string
<VAR>text</VAR> or the binary string <VAR>bin-string</VAR>.  MD5, like other such
functions, has the property that, if

<PRE>
string_hash(<VAR>x</VAR>) == string_hash(<VAR>y</VAR>)
</PRE>

<P>
then, almost certainly,

<PRE>
equal(<VAR>x</VAR>, <VAR>y</VAR>)
</PRE>

<P>
This can be useful, for example, in certain networking applications: after
sending a large piece of text across a connection, also send the result of
applying <CODE>string_hash()</CODE> to the text; if the destination site also
applies <CODE>string_hash()</CODE> to the text and gets the same result, you can be
quite confident that the large text has arrived unchanged.
</DL>

</P>


<H4><A NAME="SEC45" HREF="ProgrammersManual_toc.html#SEC45">Operations on Lists</A></H4>

<P>
<DL>
<DT><U>Function:</U> int <B>length</B> <I>(list <VAR>list</VAR>)</I>
<DD><A NAME="IDX46"></A>
Returns the number of elements in <VAR>list</VAR>.  It is also permissible to
pass a string to <CODE>length()</CODE>; see the description in the previous
section.

</P>

<PRE>
length({1, 2, 3})   =>   3
length({})          =>   0
</PRE>

</DL>

<P>
<DL>
<DT><U>Function:</U> int <B>is_member</B> <I>(<VAR>value</VAR>, list <VAR>list</VAR>)</I>
<DD><A NAME="IDX47"></A>
Returns true if there is an element of <VAR>list</VAR> that is completely
indistinguishable from <VAR>value</VAR>.  This is much the same operation as
"<CODE><VAR>value</VAR> in <VAR>list</VAR></CODE>" except that, unlike <CODE>in</CODE>, the
<CODE>is_member()</CODE> function does not treat upper- and lower-case characters in
strings as equal.

</P>

<PRE>
"Foo" in {1, "foo", #24}            =>   2
is_member("Foo", {1, "foo", #24})   =>   0
is_member("Foo", {1, "Foo", #24})   =>   2
</PRE>

</DL>

<P>
<DL>
<DT><U>Function:</U> list <B>listinsert</B> <I>(list <VAR>list</VAR>, <VAR>value</VAR> [, int <VAR>index</VAR>])</I>
<DD><A NAME="IDX48"></A>
<DT><U>Function:</U> list <B>listappend</B> <I>(list <VAR>list</VAR>, <VAR>value</VAR> [, int <VAR>index</VAR>])</I>
<DD><A NAME="IDX49"></A>
These functions return a copy of <VAR>list</VAR> with <VAR>value</VAR> added as a new
element.  <CODE>listinsert()</CODE> and <CODE>listappend()</CODE> add <VAR>value</VAR> before
and after (respectively) the existing element with the given <VAR>index</VAR>, if
provided.

</P>
<P>
The following three expressions always have the same value:

</P>

<PRE>
listinsert(<VAR>list</VAR>, <VAR>element</VAR>, <VAR>index</VAR>)
listappend(<VAR>list</VAR>, <VAR>element</VAR>, <VAR>index</VAR> - 1)
{@<VAR>list</VAR>[1..<VAR>index</VAR> - 1], <VAR>element</VAR>, @<VAR>list</VAR>[<VAR>index</VAR>..length(<VAR>list</VAR>)]}
</PRE>

<P>
If <VAR>index</VAR> is not provided, then <CODE>listappend()</CODE> adds the <VAR>value</VAR>
at the end of the list and <CODE>listinsert()</CODE> adds it at the beginning; this
usage is discouraged, however, since the same intent can be more clearly
expressed using the list-construction expression, as shown in the examples
below.

</P>

<PRE>
x = {1, 2, 3};
listappend(x, 4, 2)   =>   {1, 2, 4, 3}
listinsert(x, 4, 2)   =>   {1, 4, 2, 3}
listappend(x, 4)      =>   {1, 2, 3, 4}
listinsert(x, 4)      =>   {4, 1, 2, 3}
{@x, 4}               =>   {1, 2, 3, 4}
{4, @x}               =>   {4, 1, 2, 3}
</PRE>

</DL>

<P>
<DL>
<DT><U>Function:</U> list <B>listdelete</B> <I>(list <VAR>list</VAR>, int <VAR>index</VAR>)</I>
<DD><A NAME="IDX50"></A>
Returns a copy of <VAR>list</VAR> with the <VAR>index</VAR>th element removed.  If
<VAR>index</VAR> is not in the range <CODE>[1..length(<VAR>list</VAR>)]</CODE>, then
<CODE>E_RANGE</CODE> is raised.

</P>

<PRE>
x = {"foo", "bar", "baz"};
listdelete(x, 2)   =>   {"foo", "baz"}
</PRE>

</DL>

<P>
<DL>
<DT><U>Function:</U> list <B>listset</B> <I>(list <VAR>list</VAR>, <VAR>value</VAR>, int <VAR>index</VAR>)</I>
<DD><A NAME="IDX51"></A>
Returns a copy of <VAR>list</VAR> with the <VAR>index</VAR>th element replaced by
<VAR>value</VAR>.  If <VAR>index</VAR> is not in the range
<CODE>[1..length(<VAR>list</VAR>)]</CODE>, then <CODE>E_RANGE</CODE> is raised.

</P>

<PRE>
x = {"foo", "bar", "baz"};
listset(x, "mumble", 2)   =>   {"foo", "mumble", "baz"}
</PRE>

<P>
This function exists primarily for historical reasons; it was used heavily
before the server supported indexed assignments like <CODE>x[i] = v</CODE>.  New code
should always use indexed assignment instead of <SAMP>`listset()'</SAMP> wherever
possible.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> list <B>setadd</B> <I>(list <VAR>list</VAR>, <VAR>value</VAR>)</I>
<DD><A NAME="IDX52"></A>
<DT><U>Function:</U> list <B>setremove</B> <I>(list <VAR>list</VAR>, <VAR>value</VAR>)</I>
<DD><A NAME="IDX53"></A>
Returns a copy of <VAR>list</VAR> with the given <VAR>value</VAR> added or removed, as
appropriate.  <CODE>setadd()</CODE> only adds <VAR>value</VAR> if it is not already an
element of <VAR>list</VAR>; <VAR>list</VAR> is thus treated as a mathematical set.
<VAR>value</VAR> is added at the end of the resulting list, if at all.  Similarly,
<CODE>setremove()</CODE> returns a list identical to <VAR>list</VAR> if <VAR>value</VAR> is not
an element.  If <VAR>value</VAR> appears more than once in <VAR>list</VAR>, only the
first occurrence is removed in the returned copy.

</P>

<PRE>
setadd({1, 2, 3}, 3)         =>   {1, 2, 3}
setadd({1, 2, 3}, 4)         =>   {1, 2, 3, 4}
setremove({1, 2, 3}, 3)      =>   {1, 2}
setremove({1, 2, 3}, 4)      =>   {1, 2, 3}
setremove({1, 2, 3, 2}, 2)   =>   {1, 3, 2}
</PRE>

</DL>



<H3><A NAME="SEC46" HREF="ProgrammersManual_toc.html#SEC46">Manipulating Objects</A></H3>

<P>
Objects are, of course, the main focus of most MOO programming and, largely due
to that, there are a lot of built-in functions for manipulating them.

</P>



<H4><A NAME="SEC47" HREF="ProgrammersManual_toc.html#SEC47">Fundamental Operations on Objects</A></H4>

<P>
<DL>
<DT><U>Function:</U> obj <B>create</B> <I>(obj <VAR>parent</VAR> [, obj <VAR>owner</VAR>])</I>
<DD><A NAME="IDX54"></A>
Creates and returns a new object whose parent is <VAR>parent</VAR> and whose owner
is as described below.  Either the given <VAR>parent</VAR> object must be <CODE>#-1</CODE>
or valid and fertile (i.e., its <SAMP>`f'</SAMP> bit must be set) or else the
programmer must own <VAR>parent</VAR> or be a wizard; otherwise <CODE>E_PERM</CODE> is
raised.  <CODE>E_PERM</CODE> is also raised if <VAR>owner</VAR> is provided and not
the same as the programmer, unless the programmer is a wizard.  After the new
object is created, its <CODE>initialize</CODE> verb, if any, is called with no
arguments.

</P>
<P>
The new object is assigned the least non-negative object number that has not
yet been used for a created object.  Note that no object number is ever reused,
even if the object with that number is recycled.

</P>
<P>
The owner of the new object is either the programmer (if <VAR>owner</VAR> is not
provided), the new object itself (if <VAR>owner</VAR> was given as <CODE>#-1</CODE>), or
<VAR>owner</VAR> (otherwise).

</P>
<P>
The other built-in properties of the new object are initialized as follows:

<PRE>
name         ""
location     #-1
contents     {}
programmer   0
wizard       0
r            0
w            0
f            0
</PRE>

<P>
The function <SAMP>`is_player()'</SAMP> returns false for newly created objects.

</P>
<P>
In addition, the new object inherits all of the other properties on
<VAR>parent</VAR>.  These properties have the same permission bits as on
<VAR>parent</VAR>.  If the <SAMP>`c'</SAMP> permissions bit is set, then the owner of the
property on the new object is the same as the owner of the new object itself;
otherwise, the owner of the property on the new object is the same as that on
<VAR>parent</VAR>.  The initial value of every inherited property is <STRONG>clear</STRONG>;
see the description of the built-in function <CODE>clear_property()</CODE> for
details.

</P>
<P>
If the intended owner of the new object has a property named
<SAMP>`ownership_quota'</SAMP> and the value of that property is an integer, then
<CODE>create()</CODE> treats that value as a <STRONG>quota</STRONG>.  If the quota is less than
or equal to zero, then the quota is considered to be exhausted and
<CODE>create()</CODE> raises <CODE>E_QUOTA</CODE> instead of creating an object.
Otherwise, the quota is decremented and stored back into the
<SAMP>`ownership_quota'</SAMP> property as a part of the creation of the new object.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> none <B>chparent</B> <I>(obj <VAR>object</VAR>, obj <VAR>new-parent</VAR>)</I>
<DD><A NAME="IDX55"></A>
Changes the parent of <VAR>object</VAR> to be <VAR>new-parent</VAR>.  If <VAR>object</VAR> is
not valid, or if <VAR>new-parent</VAR> is neither valid nor equal to <CODE>#-1</CODE>,
then <CODE>E_INVARG</CODE> is raised.  If the programmer is neither a wizard or the
owner of <VAR>object</VAR>, or if <VAR>new-parent</VAR> is not fertile (i.e., its
<SAMP>`f'</SAMP> bit is not set) and the programmer is neither the owner of
<VAR>new-parent</VAR> nor a wizard, then <CODE>E_PERM</CODE> is raised.  If
<VAR>new-parent</VAR> is equal to <CODE>object</CODE> or one of its current ancestors,
<CODE>E_RECMOVE</CODE> is raised.  If <VAR>object</VAR> or one of its descendants
defines a property with the same name as one defined either on <VAR>new-parent</VAR>
or on one of its ancestors, then <CODE>E_INVARG</CODE> is raised.

</P>
<P>
Changing an object's parent can have the effect of removing some properties
from and adding some other properties to that object and all of its descendants
(i.e., its children and its children's children, etc.).  Let <VAR>common</VAR> be
the nearest ancestor that <VAR>object</VAR> and <VAR>new-parent</VAR> have in common
before the parent of <VAR>object</VAR> is changed.  Then all properties defined by
ancestors of <VAR>object</VAR> under <VAR>common</VAR> (that is, those ancestors of
<VAR>object</VAR> that are in turn descendants of <VAR>common</VAR>) are removed from
<VAR>object</VAR> and all of its descendants.  All properties defined by
<VAR>new-parent</VAR> or its ancestors under <VAR>common</VAR> are added to <VAR>object</VAR>
and all of its descendants.  As with <CODE>create()</CODE>, the newly-added
properties are given the same permission bits as they have on <VAR>new-parent</VAR>,
the owner of each added property is either the owner of the object it's added
to (if the <SAMP>`c'</SAMP> permissions bit is set) or the owner of that property on
<VAR>new-parent</VAR>, and the value of each added property is <STRONG>clear</STRONG>; see the
description of the built-in function <CODE>clear_property()</CODE> for details.  All
properties that are not removed or added in the reparenting process are
completely unchanged.

</P>
<P>
If <VAR>new-parent</VAR> is equal to <CODE>#-1</CODE>, then <VAR>object</VAR> is given no
parent at all; it becomes a new root of the parent/child hierarchy.  In this
case, all formerly inherited properties on <VAR>object</VAR> are simply removed.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> int <B>valid</B> <I>(obj <VAR>object</VAR>)</I>
<DD><A NAME="IDX56"></A>
Returns a non-zero integer (i.e., a true value) if <VAR>object</VAR> is a valid
object (one that has been created and not yet recycled) and zero (i.e., a false
value) otherwise.

</P>

<PRE>
valid(#0)    =>   1
valid(#-1)   =>   0
</PRE>

</DL>

<P>
<DL>
<DT><U>Function:</U> obj <B>parent</B> <I>(obj <VAR>object</VAR>)</I>
<DD><A NAME="IDX57"></A>
<DT><U>Function:</U> list <B>children</B> <I>(obj <VAR>object</VAR>)</I>
<DD><A NAME="IDX58"></A>
These functions return the parent and a list of the children of <VAR>object</VAR>,
respectively.  If <VAR>object</VAR> is not valid, then <CODE>E_INVARG</CODE> is raised.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> none <B>recycle</B> <I>(obj <VAR>object</VAR>)</I>
<DD><A NAME="IDX59"></A>
The given <VAR>object</VAR> is destroyed, irrevocably.  The programmer must either
own <VAR>object</VAR> or be a wizard; otherwise, <CODE>E_PERM</CODE> is raised.  If
<VAR>object</VAR> is not valid, then <CODE>E_INVARG</CODE> is raised.  The children of
<VAR>object</VAR> are reparented to the parent of <VAR>object</VAR>.  Before <VAR>object</VAR>
is recycled, each object in its contents is moved to <CODE>#-1</CODE> (implying a
call to <VAR>object</VAR>'s <CODE>exitfunc</CODE> verb, if any) and then <VAR>object</VAR>'s
<SAMP>`recycle'</SAMP> verb, if any, is called with no arguments.

</P>
<P>
After <VAR>object</VAR> is recycled, if the owner of the former object has a
property named <SAMP>`ownership_quota'</SAMP> and the value of that property is a
integer, then <CODE>recycle()</CODE> treats that value as a <STRONG>quota</STRONG> and increments
it by one, storing the result back into the <SAMP>`ownership_quota'</SAMP> property.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> int <B>object_bytes</B> <I>(obj <VAR>object</VAR>)</I>
<DD><A NAME="IDX60"></A>
Returns the number of bytes of the server's memory required to store the given
<VAR>object</VAR>, including the space used by the values of all of its non-clear
properties and by the verbs and properties defined directly on the object.
Raised <CODE>E_INVARG</CODE> if <VAR>object</VAR> is not a valid object and <CODE>E_PERM</CODE>
if the programmer is not a wizard.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> obj <B>max_object</B> <I>()</I>
<DD><A NAME="IDX61"></A>
Returns the largest object number yet assigned to a created object.  Note that
the object with this number may no longer exist; it may have been recycled.
The next object created will be assigned the object number one larger than the
value of <CODE>max_object()</CODE>.
</DL>

</P>


<H4><A NAME="SEC48" HREF="ProgrammersManual_toc.html#SEC48">Object Movement</A></H4>

<P>
<DL>
<DT><U>Function:</U> none <B>move</B> <I>(obj <VAR>what</VAR>, obj <VAR>where</VAR>)</I>
<DD><A NAME="IDX62"></A>
Changes <VAR>what</VAR>'s location to be <VAR>where</VAR>.  This is a complex process
because a number of permissions checks and notifications must be performed.
The actual movement takes place as described in the following paragraphs.

</P>
<P>
<VAR>what</VAR> should be a valid object and <VAR>where</VAR> should be either a valid
object or <CODE>#-1</CODE> (denoting a location of `nowhere'); otherwise
<CODE>E_INVARG</CODE> is raised.  The programmer must be either the owner of
<VAR>what</VAR> or a wizard; otherwise, <CODE>E_PERM</CODE> is raised.

</P>
<P>
If <VAR>where</VAR> is a valid object, then the verb-call

</P>

<PRE>
<VAR>where</VAR>:accept(<VAR>what</VAR>)
</PRE>

<P>
is performed before any movement takes place.  If the verb returns a
false value and the programmer is not a wizard, then <VAR>where</VAR> is
considered to have refused entrance to <VAR>what</VAR>; <CODE>move()</CODE> raises
<CODE>E_NACC</CODE>.  If <VAR>where</VAR> does not define an <CODE>accept</CODE> verb, then it
is treated as if it defined one that always returned false.

</P>
<P>
If moving <VAR>what</VAR> into <VAR>where</VAR> would create a loop in the containment
hierarchy (i.e., <VAR>what</VAR> would contain itself, even indirectly), then
<CODE>E_RECMOVE</CODE> is raised instead.

</P>
<P>
The <SAMP>`location'</SAMP> property of <VAR>what</VAR> is changed to be <VAR>where</VAR>, and
the <SAMP>`contents'</SAMP> properties of the old and new locations are modified
appropriately.  Let <VAR>old-where</VAR> be the location of <VAR>what</VAR> before it was
moved.  If <VAR>old-where</VAR> is a valid object, then the verb-call

</P>

<PRE>
<VAR>old-where</VAR>:exitfunc(<VAR>what</VAR>)
</PRE>

<P>
is performed and its result is ignored; it is not an error if <VAR>old-where</VAR>
does not define a verb named <SAMP>`exitfunc'</SAMP>.  Finally, if <VAR>where</VAR> and
<VAR>what</VAR> are still valid objects, and <VAR>where</VAR> is still the location of
<VAR>what</VAR>, then the verb-call

</P>

<PRE>
<VAR>where</VAR>:enterfunc(<VAR>what</VAR>)
</PRE>

<P>
is performed and its result is ignored; again, it is not an error if
<VAR>where</VAR> does not define a verb named <SAMP>`enterfunc'</SAMP>.
</DL>

</P>


<H4><A NAME="SEC49" HREF="ProgrammersManual_toc.html#SEC49">Operations on Properties</A></H4>

<P>
<DL>
<DT><U>Function:</U> list <B>properties</B> <I>(obj <VAR>object</VAR>)</I>
<DD><A NAME="IDX63"></A>
Returns a list of the names of the properties defined directly on the given
<VAR>object</VAR>, not inherited from its parent.  If <VAR>object</VAR> is not valid,
then <CODE>E_INVARG</CODE> is raised.  If the programmer does not have read
permission on <VAR>object</VAR>, then <CODE>E_PERM</CODE> is raised.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> list <B>property_info</B> <I>(obj <VAR>object</VAR>, str <VAR>prop-name</VAR>)</I>
<DD><A NAME="IDX64"></A>
<DT><U>Function:</U> none <B>set_property_info</B> <I>(obj <VAR>object</VAR>, str <VAR>prop-name</VAR>, list <VAR>info</VAR>)</I>
<DD><A NAME="IDX65"></A>
These two functions get and set (respectively) the owner and permission bits
for the property named <VAR>prop-name</VAR> on the given <VAR>object</VAR>.  If
<VAR>object</VAR> is not valid, then <CODE>E_INVARG</CODE> is raised.  If <VAR>object</VAR>
has no non-built-in property named <VAR>prop-name</VAR>, then <CODE>E_PROPNF</CODE> is
raised.  If the programmer does not have read (write) permission on the
property in question, then <CODE>property_info()</CODE> (<CODE>set_property_info()</CODE>)
raises <CODE>E_PERM</CODE>.  Property info has the following form:

</P>

<PRE>
{<VAR>owner</VAR>, <VAR>perms</VAR> [, <VAR>new-name</VAR>]}
</PRE>

<P>
where <VAR>owner</VAR> is an object, <VAR>perms</VAR> is a string containing only
characters from the set <SAMP>`r'</SAMP>, <SAMP>`w'</SAMP>, and <SAMP>`c'</SAMP>, and <VAR>new-name</VAR> is
a string; <VAR>new-name</VAR> is never part of the value returned by
<CODE>property_info()</CODE>, but it may optionally be given as part of the value
provided to <CODE>set_property_info()</CODE>.  This list is the kind of value
returned by <CODE>property_info()</CODE> and expected as the third argument to
<CODE>set_property_info()</CODE>; the latter function raises <CODE>E_INVARG</CODE> if
<VAR>owner</VAR> is not valid, if <VAR>perms</VAR> contains any illegal characters, or,
when <VAR>new-name</VAR> is given, if <VAR>prop-name</VAR> is not defined directly on
<VAR>object</VAR> or <VAR>new-name</VAR> names an existing property defined on
<VAR>object</VAR> or any of its ancestors or descendants.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> none <B>add_property</B> <I>(obj <VAR>object</VAR>, str <VAR>prop-name</VAR>, <VAR>value</VAR>, list <VAR>info</VAR>)</I>
<DD><A NAME="IDX66"></A>
Defines a new property on the given <VAR>object</VAR>, inherited by all of its
descendants; the property is named <VAR>prop-name</VAR>, its initial value is
<VAR>value</VAR>, and its owner and initial permission bits are given by <VAR>info</VAR>
in the same format as is returned by <CODE>property_info()</CODE>, described above.
If <VAR>object</VAR> is not valid or <VAR>info</VAR> does not specify a valid owner and
well-formed permission bits or <VAR>object</VAR> or its ancestors or descendants
already defines a property named <VAR>prop-name</VAR>, then <CODE>E_INVARG</CODE> is
raised.  If the programmer does not have write permission on <VAR>object</VAR> or
if the owner specified by <VAR>info</VAR> is not the programmer and the programmer
is not a wizard, then <CODE>E_PERM</CODE> is raised.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> none <B>delete_property</B> <I>(obj <VAR>object</VAR>, str <VAR>prop-name</VAR>)</I>
<DD><A NAME="IDX67"></A>
Removes the property named <VAR>prop-name</VAR> from the given <VAR>object</VAR> and all
of its descendants.  If <VAR>object</VAR> is not valid, then <CODE>E_INVARG</CODE> is
raised.  If the programmer does not have write permission on <VAR>object</VAR>,
then <CODE>E_PERM</CODE> is raised.  If <VAR>object</VAR> does not directly define a
property named <VAR>prop-name</VAR> (as opposed to inheriting one from its parent),
then <CODE>E_PROPNF</CODE> is raised.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> int <B>is_clear_property</B> <I>(obj <VAR>object</VAR>, str <VAR>prop-name</VAR>)</I>
<DD><A NAME="IDX68"></A>
<DT><U>Function:</U> none <B>clear_property</B> <I>(obj <VAR>object</VAR>, str <VAR>prop-name</VAR>)</I>
<DD><A NAME="IDX69"></A>
These two functions test for clear and set to clear, respectively, the property
named <VAR>prop-name</VAR> on the given <VAR>object</VAR>.  If <VAR>object</VAR> is not valid,
then <CODE>E_INVARG</CODE> is raised.  If <VAR>object</VAR> has no non-built-in property
named <VAR>prop-name</VAR>, then <CODE>E_PROPNF</CODE> is raised.  If the programmer
does not have read (write) permission on the property in question, then
<CODE>is_clear_property()</CODE> (<CODE>clear_property()</CODE>) raises <CODE>E_PERM</CODE>.
If a property is clear, then when the value of that property is queried the
value of the parent's property of the same name is returned.  If the parent's
property is clear, then the parent's parent's value is examined, and so on.
If <VAR>object</VAR> is the definer of the property <VAR>prop-name</VAR>, as opposed to
an inheritor of the property, then <CODE>clear_property()</CODE> raises
<CODE>E_INVARG</CODE>.
</DL>

</P>


<H4><A NAME="SEC50" HREF="ProgrammersManual_toc.html#SEC50">Operations on Verbs</A></H4>

<P>
<DL>
<DT><U>Function:</U> list <B>verbs</B> <I>(obj <VAR>object</VAR>)</I>
<DD><A NAME="IDX70"></A>
Returns a list of the names of the verbs defined directly on the given
<VAR>object</VAR>, not inherited from its parent.  If <VAR>object</VAR> is not valid,
then <CODE>E_INVARG</CODE> is raised.  If the programmer does not have read
permission on <VAR>object</VAR>, then <CODE>E_PERM</CODE> is raised.
</DL>

</P>
<P>
Most of the remaining operations on verbs accept a string containing the verb's
name to identify the verb in question.  Because verbs can have multiple names
and because an object can have multiple verbs with the same name, this practice
can lead to difficulties.  To most unambiguously refer to a particular verb,
one can instead use a positive integer, the index of the verb in the list
returned by <CODE>verbs()</CODE>, described above.

</P>
<P>
For example, suppose that <CODE>verbs(#34)</CODE> returns this list:

</P>

<PRE>
{"foo", "bar", "baz", "foo"}
</PRE>

<P>
Object <CODE>#34</CODE> has two verbs named <SAMP>`foo'</SAMP> defined on it (this may not be
an error, if the two verbs have different command syntaxes).  To refer
unambiguously to the first one in the list, one uses the integer 1; to refer to
the other one, one uses 4.

</P>
<P>
In the function descriptions below, an argument named <VAR>verb-desc</VAR> is either
a string containing the name of a verb or else a positive integer giving the
index of that verb in its defining object's <CODE>verbs()</CODE> list.

</P>

<BLOCKQUOTE>
<P>
For historical reasons, there is also a second, inferior mechanism for
referring to verbs with numbers, but its use is strongly discouraged.  If the
property <CODE>$server_options.support_numeric_verbname_strings</CODE> exists with a
true value, then functions on verbs will also accept a numeric string (e.g.,
<CODE>"4"</CODE>) as a verb descriptor.  The decimal integer in the string works
more-or-less like the positive integers described above, but with two
significant differences:

</P>

<OL>
<LI>

The numeric string is a <EM>zero-based</EM> index into <CODE>verbs()</CODE>; that is,
in the string case, you would use the number one less than what you would use
in the positive integer case.

<LI>

When there exists a verb whose actual name looks like a decimal integer, this
numeric-string notation is ambiguous; the server will in all cases assume that
the reference is to the first verb in the list for which the given string could
be a name, either in the normal sense or as a numeric index.
</OL>

<P>
Clearly, this older mechanism is more difficult and risky to use; new code
should only be written to use the current mechanism, and old code using numeric
strings should be modified not to do so.
</BLOCKQUOTE>

<P>
<DL>
<DT><U>Function:</U> list <B>verb_info</B> <I>(obj <VAR>object</VAR>, str <VAR>verb-desc</VAR>)</I>
<DD><A NAME="IDX71"></A>
<DT><U>Function:</U> none <B>set_verb_info</B> <I>(obj <VAR>object</VAR>, str <VAR>verb-desc</VAR>, list <VAR>info</VAR>)</I>
<DD><A NAME="IDX72"></A>
These two functions get and set (respectively) the owner, permission bits, and
name(s) for the verb as specified by <VAR>verb-desc</VAR> on the given <VAR>object</VAR>.
If <VAR>object</VAR> is not valid, then <CODE>E_INVARG</CODE> is raised.  If <VAR>object</VAR>
does not define a verb as specified by <VAR>verb-desc</VAR>, then <CODE>E_VERBNF</CODE> is
raised.  If the programmer does not have read (write) permission on the verb in
question, then <CODE>verb_info()</CODE> (<CODE>set_verb_info()</CODE>) raises
<CODE>E_PERM</CODE>.  Verb info has the following form:

</P>

<PRE>
{<VAR>owner</VAR>, <VAR>perms</VAR>, <VAR>names</VAR>}
</PRE>

<P>
where <VAR>owner</VAR> is an object, <VAR>perms</VAR> is a string containing only
characters from the set <SAMP>`r'</SAMP>, <SAMP>`w'</SAMP>, <SAMP>`x'</SAMP>, and <SAMP>`d'</SAMP>, and
<VAR>names</VAR> is a string.  This is the kind of value returned by
<CODE>verb_info()</CODE> and expected as the third argument to
<CODE>set_verb_info()</CODE>.  <CODE>set_verb_info()</CODE> raises <CODE>E_INVARG</CODE> if
<VAR>owner</VAR> is not valid, if <VAR>perms</VAR> contains any illegal characters, or if
<VAR>names</VAR> is the empty string or consists entirely of spaces; it raises
<CODE>E_PERM</CODE> if <VAR>owner</VAR> is not the programmer and the programmer is not a
wizard.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> list <B>verb_args</B> <I>(obj <VAR>object</VAR>, str <VAR>verb-desc</VAR>)</I>
<DD><A NAME="IDX73"></A>
<DT><U>Function:</U> none <B>set_verb_args</B> <I>(obj <VAR>object</VAR>, str <VAR>verb-desc</VAR>, list <VAR>args</VAR>)</I>
<DD><A NAME="IDX74"></A>
These two functions get and set (respectively) the direct-object, preposition,
and indirect-object specifications for the verb as specified by <VAR>verb-desc</VAR>
on the given <VAR>object</VAR>.  If <VAR>object</VAR> is not valid, then <CODE>E_INVARG</CODE>
is raised.  If <VAR>object</VAR> does not define a verb as specified by
<VAR>verb-desc</VAR>, then <CODE>E_VERBNF</CODE> is raised.  If the programmer does not
have read (write) permission on the verb in question, then <CODE>verb_args()</CODE>
(<CODE>set_verb_args()</CODE>) raises <CODE>E_PERM</CODE>.  Verb args specifications have
the following form:

</P>

<PRE>
{<VAR>dobj</VAR>, <VAR>prep</VAR>, <VAR>iobj</VAR>}
</PRE>

<P>
where <VAR>dobj</VAR> and <VAR>iobj</VAR> are strings drawn from the set <CODE>"this"</CODE>,
<CODE>"none"</CODE>, and <CODE>"any"</CODE>, and <VAR>prep</VAR> is a string that is either
<CODE>"none"</CODE>, <CODE>"any"</CODE>, or one of the prepositional phrases listed much
earlier in the description of verbs in the first chapter.  This is the kind of
value returned by <CODE>verb_args()</CODE> and expected as the third argument to
<CODE>set_verb_args()</CODE>.  Note that for <CODE>set_verb_args()</CODE>, <VAR>prep</VAR> must
be only one of the prepositional phrases, not (as is shown in that table) a set
of such phrases separated by <SAMP>`/'</SAMP> characters.  <CODE>set_verb_args</CODE> raises
<CODE>E_INVARG</CODE> if any of the <VAR>dobj</VAR>, <VAR>prep</VAR>, or <VAR>iobj</VAR> strings is
illegal.

</P>

<PRE>
verb_args($container, "take")
                    =>   {"any", "out of/from inside/from", "this"}
set_verb_args($container, "take", {"any", "from", "this"})
</PRE>

</DL>

<P>
<DL>
<DT><U>Function:</U> none <B>add_verb</B> <I>(obj <VAR>object</VAR>, list <VAR>info</VAR>, list <VAR>args</VAR>)</I>
<DD><A NAME="IDX75"></A>
Defines a new verb on the given <VAR>object</VAR>.  The new verb's owner, permission
bits and name(s) are given by <VAR>info</VAR> in the same format as is returned by
<CODE>verb_info()</CODE>, described above.  The new verb's direct-object,
preposition, and indirect-object specifications are given by <VAR>args</VAR> in the
same format as is returned by <CODE>verb_args</CODE>, described above.  The new verb
initially has the empty program associated with it; this program does nothing
but return an unspecified value.

</P>
<P>
If <VAR>object</VAR> is not valid, or <VAR>info</VAR> does not specify a valid owner and
well-formed permission bits and verb names, or <VAR>args</VAR> is not a legitimate
syntax specification, then <CODE>E_INVARG</CODE> is raised.  If the programmer does
not have write permission on <VAR>object</VAR> or if the owner specified by
<VAR>info</VAR> is not the programmer and the programmer is not a wizard, then
<CODE>E_PERM</CODE> is raised.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> none <B>delete_verb</B> <I>(obj <VAR>object</VAR>, str <VAR>verb-desc</VAR>)</I>
<DD><A NAME="IDX76"></A>
Removes the verb as specified by <VAR>verb-desc</VAR> from the given <VAR>object</VAR>.
If <VAR>object</VAR> is not valid, then <CODE>E_INVARG</CODE> is raised.  If the
programmer does not have write permission on <VAR>object</VAR>, then <CODE>E_PERM</CODE>
is raised.  If <VAR>object</VAR> does not define a verb as specified by
<VAR>verb-desc</VAR>, then <CODE>E_VERBNF</CODE> is raised.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> list <B>verb_code</B> <I>(obj <VAR>object</VAR>, str <VAR>verb-desc</VAR> [, <VAR>fully-paren</VAR> [, <VAR>indent</VAR>]])</I>
<DD><A NAME="IDX77"></A>
<DT><U>Function:</U> list <B>set_verb_code</B> <I>(obj <VAR>object</VAR>, str <VAR>verb-desc</VAR>, list <VAR>code</VAR>)</I>
<DD><A NAME="IDX78"></A>
These functions get and set (respectively) the MOO-code program associated with
the verb as specified by <VAR>verb-desc</VAR> on <VAR>object</VAR>.  The program is
represented as a list of strings, one for each line of the program; this is the
kind of value returned by <CODE>verb_code()</CODE> and expected as the third argument
to <CODE>set_verb_code()</CODE>.  For <CODE>verb_code()</CODE>, the expressions in the
returned code are usually written with the minimum-necessary parenthesization;
if <VAR>full-paren</VAR> is true, then all expressions are fully parenthesized.
Also for <CODE>verb_code()</CODE>, the lines in the returned code are usually not
indented at all; if <VAR>indent</VAR> is true, each line is indented to better show
the nesting of statements.

</P>
<P>
If <VAR>object</VAR> is not valid, then <CODE>E_INVARG</CODE> is raised.  If <VAR>object</VAR>
does not define a verb as specified by <VAR>verb-desc</VAR>, then <CODE>E_VERBNF</CODE> is
raised.  If the programmer does not have read (write) permission on the verb in
question, then <CODE>verb_code()</CODE> (<CODE>set_verb_code()</CODE>) raises
<CODE>E_PERM</CODE>.  If the programmer is not, in fact. a programmer, then
<CODE>E_PERM</CODE> is raised.

</P>
<P>
For <CODE>set_verb_code()</CODE>, the result is a list of strings, the error messages
generated by the MOO-code compiler during processing of <VAR>code</VAR>.  If the
list is non-empty, then <CODE>set_verb_code()</CODE> did not install <VAR>code</VAR>; the
program associated with the verb in question is unchanged.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> list <B>disassemble</B> <I>(obj <VAR>object</VAR>, str <VAR>verb-desc</VAR>)</I>
<DD><A NAME="IDX79"></A>
Returns a (longish) list of strings giving a listing of the server's internal
"compiled" form of the verb as specified by <VAR>verb-desc</VAR> on <VAR>object</VAR>.
This format is not documented and may indeed change from release to release,
but some programmers may nonetheless find the output of <CODE>disassemble()</CODE>
interesting to peruse as a way to gain a deeper appreciation of how the server
works.

</P>
<P>
If <VAR>object</VAR> is not valid, then <CODE>E_INVARG</CODE> is raised.  If <VAR>object</VAR>
does not define a verb as specified by <VAR>verb-desc</VAR>, then <CODE>E_VERBNF</CODE> is
raised.  If the programmer does not have read permission on the verb in
question, then <CODE>disassemble()</CODE> raises <CODE>E_PERM</CODE>.
</DL>

</P>


<H4><A NAME="SEC51" HREF="ProgrammersManual_toc.html#SEC51">Operations on Player Objects</A></H4>

<P>
<DL>
<DT><U>Function:</U> list <B>players</B> <I>()</I>
<DD><A NAME="IDX80"></A>
Returns a list of the object numbers of all player objects in the database.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> int <B>is_player</B> <I>(obj <VAR>object</VAR>)</I>
<DD><A NAME="IDX81"></A>
Returns a true value if the given <VAR>object</VAR> is a player object and a false
value otherwise.  If <VAR>object</VAR> is not valid, <CODE>E_INVARG</CODE> is raised.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> none <B>set_player_flag</B> <I>(obj <VAR>object</VAR>, <VAR>value</VAR>)</I>
<DD><A NAME="IDX82"></A>
Confers or removes the "player object" status of the given <VAR>object</VAR>,
depending upon the truth value of <VAR>value</VAR>.  If <VAR>object</VAR> is not valid,
<CODE>E_INVARG</CODE> is raised.  If the programmer is not a wizard, then
<CODE>E_PERM</CODE> is raised.

</P>
<P>
If <VAR>value</VAR> is true, then <VAR>object</VAR> gains (or keeps) "player object"
status: it will be an element of the list returned by <CODE>players()</CODE>, the
expression <CODE>is_player(<VAR>object</VAR>)</CODE> will return true, and the server will
treat a call to <CODE>$do_login_command()</CODE> that returns <VAR>object</VAR> as
logging in the current connection.

</P>
<P>
If <VAR>value</VAR> is false, the <VAR>object</VAR> loses (or continues to lack) "player
object" status: it will not be an element of the list returned by
<CODE>players()</CODE>, the expression <CODE>is_player(<VAR>object</VAR>)</CODE> will return
false, and users cannot connect to <VAR>object</VAR> by name when they log into the
server.  In addition, if a user is connected to <VAR>object</VAR> at the time that
it loses "player object" status, then that connection is immediately broken,
just as if <CODE>boot_player(<VAR>object</VAR>)</CODE> had been called (see the
description of <CODE>boot_player()</CODE> below).
</DL>

</P>


<H3><A NAME="SEC52" HREF="ProgrammersManual_toc.html#SEC52">Operations on Network Connections</A></H3>

<P>
<DL>
<DT><U>Function:</U> list <B>connected_players</B> <I>([<VAR>include-all</VAR>])</I>
<DD><A NAME="IDX83"></A>
Returns a list of the object numbers of those player objects with
currently-active connections.  If <VAR>include-all</VAR> is provided and true, then
the list includes the object numbers associated with <EM>all</EM> current
connections, including ones that are outbound and/or not yet logged-in.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> int <B>connected_seconds</B> <I>(obj <VAR>player</VAR>)</I>
<DD><A NAME="IDX84"></A>
<DT><U>Function:</U> int <B>idle_seconds</B> <I>(obj <VAR>player</VAR>)</I>
<DD><A NAME="IDX85"></A>
These functions return the number of seconds that the currently-active
connection to <VAR>player</VAR> has existed and been idle, respectively.  If
<VAR>player</VAR> is not the object number of a player object with a
currently-active connection, then <CODE>E_INVARG</CODE> is raised.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> none <B>notify</B> <I>(obj <VAR>conn</VAR>, str <VAR>string</VAR> [, <VAR>no-flush</VAR>])</I>
<DD><A NAME="IDX86"></A>
Enqueues <VAR>string</VAR> for output (on a line by itself) on the connection
<VAR>conn</VAR>.  If the programmer is not <VAR>conn</VAR> or a wizard, then
<CODE>E_PERM</CODE> is raised.  If <VAR>conn</VAR> is not a currently-active connection,
then this function does nothing.  Output is normally written to connections
only between tasks, not during execution.

</P>
<P>
The server will not queue an arbitrary amount of output for a connection; the
<CODE>MAX_QUEUED_OUTPUT</CODE> compilation option (in <SAMP>`options.h'</SAMP>) controls the
limit.  When an attempt is made to enqueue output that would take the server
over its limit, it first tries to write as much output as possible to the
connection without having to wait for the other end.  If that doesn't result in
the new output being able to fit in the queue, the server starts throwing away
the oldest lines in the queue until the new ouput will fit.  The server
remembers how many lines of output it has `flushed' in this way and, when next
it can succeed in writing anything to the connection, it first writes a line
like <CODE>&#62;&#62; Network buffer overflow: <VAR>X</VAR> lines of output to you have been
lost &#60;&#60;</CODE> where <VAR>X</VAR> is the number of flushed lines.

</P>
<P>
If <VAR>no-flush</VAR> is provided and true, then <CODE>notify()</CODE> never flushes any
output from the queue; instead it immediately returns false.  <CODE>Notify()</CODE>
otherwise always returns true.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> int <B>buffered_output_length</B> <I>([obj <VAR>conn</VAR>])</I>
<DD><A NAME="IDX87"></A>
Returns the number of bytes currently buffered for output to the connection
<VAR>conn</VAR>.  If <VAR>conn</VAR> is not provided, returns the maximum number of bytes
that will be buffered up for output on any connection.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> str <B>read</B> <I>([obj <VAR>conn</VAR> [, <VAR>non-blocking</VAR>]])</I>
<DD><A NAME="IDX88"></A>
Reads and returns a line of input from the connection <VAR>conn</VAR> (or, if not
provided, from the player that typed the command that initiated the current
task).  If <VAR>non-blocking</VAR> is false or not provided, this function suspends
the current task, resuming it when there is input available to be read.  If
<VAR>non-blocking</VAR> is provided and true, this function never suspends the
calling task; if there is no input currently available for input, <CODE>read()</CODE>
simply returns 0 immediately.

</P>
<P>
If <VAR>player</VAR> is provided, then the programmer must either be a wizard or the
owner of <CODE>player</CODE>; if <CODE>player</CODE> is not provided, then <CODE>read()</CODE>
may only be called by a wizard and only in the task that was last spawned by a
command from the connection in question.  Otherwise, <CODE>E_PERM</CODE> is raised.
If the given <CODE>player</CODE> is not currently connected and has no pending lines
of input, or if the connection is closed while a task is waiting for input but
before any lines of input are received, then <CODE>read()</CODE> raises
<CODE>E_INVARG</CODE>.

</P>
<P>
The restriction on the use of <CODE>read()</CODE> without any arguments preserves the
following simple invariant: if input is being read from a player, it is for the
task started by the last command that player typed.  This invariant adds
responsibility to the programmer, however.  If your program calls another verb
before doing a <CODE>read()</CODE>, then either that verb must not suspend or else
you must arrange that no commands will be read from the connection in the
meantime.  The most straightforward way to do this is to call

<PRE>
set_connection_option(player, "hold-input", 1)
</PRE>

<P>
before any task suspension could happen, then make all of your calls to
<CODE>read()</CODE> and other code that might suspend, and finally call

<PRE>
set_connection_option(player, "hold-input", 0)
</PRE>

<P>
to allow commands once again to be read and interpreted normally.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> none <B>force_input</B> <I>(obj <VAR>conn</VAR>, str <VAR>line</VAR> [, <VAR>at-front</VAR>])</I>
<DD><A NAME="IDX89"></A>
Inserts the string <VAR>line</VAR> as an input task in the queue for the connection
<VAR>conn</VAR>, just as if it had arrived as input over the network.  If
<VAR>at_front</VAR> is provided and true, then the new line of input is put at the
front of <VAR>conn</VAR>'s queue, so that it will be the very next line of input
processed even if there is already some other input in that queue.  Raises
<CODE>E_INVARG</CODE> if <VAR>conn</VAR> does not specify a current connection and
<CODE>E_PERM</CODE> if the programmer is neither <VAR>conn</VAR> nor a wizard.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> none <B>flush_input</B> <I>(obj <VAR>conn</VAR> [<VAR>show-messages</VAR>])</I>
<DD><A NAME="IDX90"></A>
Performs the same actions as if the connection <VAR>conn</VAR>'s defined flush
command had been received on that connection, i.e., removes all pending lines
of input from <VAR>conn</VAR>'s queue and, if <VAR>show-messages</VAR> is provided and
true, prints a message to <VAR>conn</VAR> listing the flushed lines, if any.  See
the chapter on server assumptions about the database for more information about
a connection's defined flush command.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> list <B>output_delimiters</B> <I>(obj <VAR>player</VAR>)</I>
<DD><A NAME="IDX91"></A>
Returns a list of two strings, the current <STRONG>output prefix</STRONG> and <STRONG>output
suffix</STRONG> for <VAR>player</VAR>.  If <VAR>player</VAR> does not have an active network
connection, then <CODE>E_INVARG</CODE> is raised.  If either string is currently
undefined, the value <CODE>""</CODE> is used instead.  See the discussion of the
<CODE>PREFIX</CODE> and <CODE>SUFFIX</CODE> commands in the next chapter for more
information about the output prefix and suffix.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> none <B>boot_player</B> <I>(obj <VAR>player</VAR>)</I>
<DD><A NAME="IDX92"></A>
Marks for disconnection any currently-active connection to the given
<VAR>player</VAR>.  The connection will not actually be closed until the
currently-running task returns or suspends, but all MOO functions (such as
<CODE>notify()</CODE>, <CODE>connected_players()</CODE>, and the like) immediately behave
as if the connection no longer exists.  If the programmer is not either a
wizard or the same as <VAR>player</VAR>, then <CODE>E_PERM</CODE> is raised.  If there
is no currently-active connection to <VAR>player</VAR>, then this function does
nothing.

</P>
<P>
If there was a currently-active connection, then the following verb call is
made when the connection is actually closed:

</P>

<PRE>
$user_disconnected(<VAR>player</VAR>)
</PRE>

<P>
It is not an error if this verb does not exist; the call is simply skipped.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> str <B>connection_name</B> <I>(obj <VAR>player</VAR>)</I>
<DD><A NAME="IDX93"></A>
Returns a network-specific string identifying the connection being used by the
given player.  If the programmer is not a wizard and not <VAR>player</VAR>, then
<CODE>E_PERM</CODE> is raised.  If <VAR>player</VAR> is not currently connected, then
<CODE>E_INVARG</CODE> is raised.

</P>
<P>
For the TCP/IP networking configurations, for in-bound connections, the string
has the form

<PRE>
"port <VAR>lport</VAR> from <VAR>host</VAR>, port <VAR>port</VAR>"
</PRE>

<P>
where <VAR>lport</VAR> is the decimal TCP listening port on which the connection
arrived, <VAR>host</VAR> is either the name or decimal TCP address of the host from
which the player is connected, and <VAR>port</VAR> is the decimal TCP port of the
connection on that host.

</P>
<P>
For outbound TCP/IP connections, the string has the form

<PRE>
"port <VAR>lport</VAR> to <VAR>host</VAR>, port <VAR>port</VAR>"
</PRE>

<P>
where <VAR>lport</VAR> is the decimal local TCP port number from which the
connection originated, <VAR>host</VAR> is either the name or decimal TCP address of
the host to which the connection was opened, and <VAR>port</VAR> is the decimal TCP
port of the connection on that host.

</P>
<P>
For the System V `local' networking configuration, the string is the UNIX login
name of the connecting user or, if no such name can be found, something of the
form

<PRE>
"User #<VAR>number</VAR>"
</PRE>

<P>
where <VAR>number</VAR> is a UNIX numeric user ID.

</P>
<P>
For the other networking configurations, the string is the same for all
connections and, thus, useless.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> none <B>set_connection_option</B> <I>(obj <VAR>conn</VAR>, str <VAR>option</VAR>, <VAR>value</VAR>)</I>
<DD><A NAME="IDX94"></A>
Controls a number of optional behaviors associated the connection <VAR>conn</VAR>.
Raises <CODE>E_INVARG</CODE> if <VAR>conn</VAR> does not specify a current connection and
<CODE>E_PERM</CODE> if the programmer is neither <VAR>conn</VAR> nor a wizard.  The
following values for <VAR>option</VAR> are currently supported:

</P>
<DL COMPACT>

<DT><CODE>"hold-input"</CODE>
<DD>
If <VAR>value</VAR> is true, then input received on <VAR>conn</VAR> will never be treated
as a command; instead, it will remain in the queue until retrieved by a call to
<CODE>read()</CODE>.

<DT><CODE>"client-echo"</CODE>
<DD>
Send the Telnet Protocol <SAMP>`WONT ECHO'</SAMP> or <SAMP>`WILL ECHO'</SAMP> command,
depending on whether <VAR>value</VAR> is true or false, respectively.  For clients
that support the Telnet Protocol, this should toggle whether or not the client
echoes locally the characters typed by the user.  Note that the server itself
never echoes input characters under any circumstances.  (This option is only
available under the TCP/IP networking configurations.)

<DT><CODE>"binary"</CODE>
<DD>
If <VAR>value</VAR> is true, then both input from and output to <VAR>conn</VAR> can
contain arbitrary bytes.  Input from a connection in binary mode is not broken
into lines at all; it is delivered to either the read() function or the
built-in command parser as <STRONG>binary strings</STRONG>, in whatever size chunks come
back from the operating system.  (See the early section on MOO value types for
a description of the binary string representation.)  For output to a connection
in binary mode, the second argument to `notify()' must be a binary string; if
it is malformed, E_INVARG is raised.

<DT><CODE>"flush-command"</CODE>
<DD>
If <VAR>value</VAR> is a non-empty string, then it becomes the new <STRONG>flush</STRONG>
command for this connection, by which the player can flush all queued input
that has not yet been processed by the server.  If <VAR>value</VAR> is not a
non-empty string, then <VAR>conn</VAR> is set to have no flush command at all.  The
default value of this option can be set via the property
<CODE>$server_options.default_flush_command</CODE>; see the chapter on server
assumptions about the database for details.
</DL>
</DL>

<P>
<DL>
<DT><U>Function:</U> list <B>connection_options</B> <I>(obj <VAR>conn</VAR>)</I>
<DD><A NAME="IDX95"></A>
Returns a list of <CODE>{<VAR>name</VAR>, <VAR>value</VAR>}</CODE> pairs describing the
current settings of all of the allowed options for the connection <VAR>conn</VAR>.
Raises <CODE>E_INVARG</CODE> if <VAR>conn</VAR> does not specify a current connection and
<CODE>E_PERM</CODE> if the programmer is neither <VAR>conn</VAR> nor a wizard.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> value <B>connection_option</B> <I>(obj <VAR>conn</VAR>, str <VAR>name</VAR>)</I>
<DD><A NAME="IDX96"></A>
Returns the current setting of the option <VAR>name</VAR> for the connection
<VAR>conn</VAR>.  Raises <CODE>E_INVARG</CODE> if <VAR>conn</VAR> does not specify a current
connection and <CODE>E_PERM</CODE> if the programmer is neither <VAR>conn</VAR> nor a
wizard.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> obj <B>open_network_connection</B> <I>(<VAR>value</VAR>, ...)</I>
<DD><A NAME="IDX97"></A>
Establishes a network connection to the place specified by the arguments and
more-or-less pretends that a new, normal player connection has been established
from there.  The new connection, as usual, will not be logged in initially and
will have a negative object number associated with it for use with
<CODE>read()</CODE>, <CODE>notify()</CODE>, and <CODE>boot_player()</CODE>.  This object number
is the value returned by this function.

</P>
<P>
If the programmer is not a wizard or if the <CODE>OUTBOUND_NETWORK</CODE> compilation
option was not used in building the server, then <CODE>E_PERM</CODE> is raised.  If
the network connection cannot be made for some reason, then other errors will
be returned, depending upon the particular network implementation in use.

</P>
<P>
For the TCP/IP network implementations (the only ones as of this writing that
support outbound connections), there must be two arguments, a string naming a
host (possibly using the numeric Internet syntax) and an integer specifying a TCP
port.  If a connection cannot be made because the host does not exist, the port
does not exist, the host is not reachable or refused the connection,
<CODE>E_INVARG</CODE> is raised.  If the connection cannot be made for other
reasons, including resource limitations, then <CODE>E_QUOTA</CODE> is raised.

</P>
<P>
The outbound connection process involves certain steps that can take quite a
long time, during which the server is not doing anything else, including
responding to user commands and executing MOO tasks.  See the chapter on
server assumptions about the database for details about how the server limits
the amount of time it will wait for these steps to successfully complete.

</P>
<P>
It is worth mentioning one tricky point concerning the use of this function.
Since the server treats the new connection pretty much like any normal player
connection, it will naturally try to parse any input from that connection as
commands in the usual way.  To prevent this treatment, you should use
<CODE>set_connection_option()</CODE> to set the <CODE>"hold-input"</CODE> option true on
the connection.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> value <B>listen</B> <I>(obj <VAR>object</VAR>, <VAR>point</VAR> [, <VAR>print-messages</VAR>])</I>
<DD><A NAME="IDX98"></A>
Create a new point at which the server will listen for network connections,
just as it does normally.  <VAR>Object</VAR> is the object whose verbs
<CODE>do_login_command</CODE>, <CODE>do_command</CODE>, <CODE>do_out_of_band_command</CODE>,
<CODE>user_connected</CODE>, <CODE>user_created</CODE>, <CODE>user_reconnected</CODE>,
<CODE>user_disconnected</CODE>, and <CODE>user_client_disconnected</CODE> will be called at
appropriate points, just as these verbs are called on <CODE>#0</CODE> for normal
connections.  (See the chapter on server assumptions about the database for the
complete story on when these functions are called.)  <VAR>Point</VAR> is a
network-configuration-specific parameter describing the listening point.  If
<VAR>print-messages</VAR> is provided and true, then the various
database-configurable messages (also detailed in the chapter on server
assumptions) will be printed on connections received at the new listening
point.  <CODE>Listen()</CODE> returns <VAR>canon</VAR>, a `canonicalized' version of
<VAR>point</VAR>, with any configuration-specific defaulting or aliasing accounted
for.

</P>
<P>
This raises <CODE>E_PERM</CODE> if the programmer is not a wizard, <CODE>E_INVARG</CODE> if
<VAR>object</VAR> is invalid or there is already a listening point described by
<VAR>point</VAR>, and <CODE>E_QUOTA</CODE> if some network-configuration-specific error
occurred.

</P>
<P>
For the TCP/IP configurations, <VAR>point</VAR> is a TCP port number on which to
listen and <VAR>canon</VAR> is equal to <VAR>point</VAR> unless <VAR>point</VAR> is zero, in
which case <VAR>canon</VAR> is a port number assigned by the operating system.

</P>
<P>
For the local multi-user configurations, <VAR>point</VAR> is the UNIX file name to
be used as the connection point and <VAR>canon</VAR> is always equal to <VAR>point</VAR>.

</P>
<P>
In the single-user configuration, the can be only one listening point at a
time; <VAR>point</VAR> can be any value at all and <VAR>canon</VAR> is always zero.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> none <B>unlisten</B> <I>(<VAR>canon</VAR>)</I>
<DD><A NAME="IDX99"></A>
Stop listening for connections on the point described by <VAR>canon</VAR>, which
should be the second element of some element of the list returned by
<CODE>listeners()</CODE>.  Raises <CODE>E_PERM</CODE> if the programmer is not a wizard and
<CODE>E_INVARG</CODE> if there does not exist a listener with that description.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> list <B>listeners</B> <I>()</I>
<DD><A NAME="IDX100"></A>
Returns a list describing all existing listening points, including the default
one set up automatically by the server when it was started (unless that one has
since been destroyed by a call to <CODE>unlisten()</CODE>).  Each element of the list
has the following form:

</P>

<PRE>
{<VAR>object</VAR>, <VAR>canon</VAR>, <VAR>print-messages</VAR>}
</PRE>

<P>
where <VAR>object</VAR> is the first argument given in the call to <CODE>listen()</CODE>
to create this listening point, <VAR>print-messages</VAR> is true if the third
argument in that call was provided and true, and <VAR>canon</VAR> was the value
returned by that call.  (For the initial listening point, <VAR>object</VAR> is
<CODE>#0</CODE>, <VAR>canon</VAR> is determined by the command-line arguments or a
network-configuration-specific default, and <VAR>print-messages</VAR> is true.)
</DL>

</P>
<P>
Please note that there is nothing special about the initial listening point
created by the server when it starts; you can use <CODE>unlisten()</CODE> on it just
as if it had been created by <CODE>listen()</CODE>.  This can be useful; for example,
under one of the TCP/IP configurations, you might start up your server on some
obscure port, say 12345, connect to it by yourself for a while, and then open
it up to normal users by evaluating the statments

<PRE>
unlisten(12345); listen(#0, 7777, 1)
</PRE>



<H3><A NAME="SEC53" HREF="ProgrammersManual_toc.html#SEC53">Operations Involving Times and Dates</A></H3>

<P>
<DL>
<DT><U>Function:</U> int <B>time</B> <I>()</I>
<DD><A NAME="IDX101"></A>
Returns the current time, represented as the number of seconds that have
elapsed since midnight on 1 January 1970, Greenwich Mean Time.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> str <B>ctime</B> <I>([int <VAR>time</VAR>])</I>
<DD><A NAME="IDX102"></A>
Interprets <VAR>time</VAR> as a time, using the same representation as given in the
description of <CODE>time()</CODE>, above, and converts it into a 28-character,
human-readable string in the following format:

</P>

<PRE>
Mon Aug 13 19:13:20 1990 PDT
</PRE>

<P>
If the current day of the month is less than 10, then an extra blank appears
between the month and the day:

</P>

<PRE>
Mon Apr  1 14:10:43 1991 PST
</PRE>

<P>
If <VAR>time</VAR> is not provided, then the current time is used.

</P>
<P>
Note that <CODE>ctime()</CODE> interprets <VAR>time</VAR> for the local time zone of the
computer on which the MOO server is running.
</DL>

</P>


<H3><A NAME="SEC54" HREF="ProgrammersManual_toc.html#SEC54">MOO-Code Evaluation and Task Manipulation</A></H3>

<P>
<DL>
<DT><U>Function:</U> none <B>raise</B> <I>(<VAR>code</VAR> [, str <VAR>message</VAR> [, <VAR>value</VAR>]])</I>
<DD><A NAME="IDX103"></A>
Raises <VAR>code</VAR> as an error in the same way as other MOO expressions,
statements, and functions do.  <VAR>Message</VAR>, which defaults to the value of
<CODE>tostr(<VAR>code</VAR>)</CODE>, and <VAR>value</VAR>, which defaults to zero, are made
available to any <CODE>try</CODE>-<CODE>except</CODE> statements that catch the error.  If
the error is not caught, then <VAR>message</VAR> will appear on the first line of
the traceback printed to the user.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> value <B>call_function</B> <I>(str <VAR>func-name</VAR>, <VAR>arg</VAR>, ...)</I>
<DD><A NAME="IDX104"></A>
Calls the built-in function named <VAR>func-name</VAR>, passing the given arguments,
and returns whatever that function returns.  Raises <CODE>E_INVARG</CODE> if
<VAR>func-name</VAR> is not recognized as the name of a known built-in function.
This allows you to compute the name of the function to call and, in particular,
allows you to write a call to a built-in function that may or may not exist in
the particular version of the server you're using.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> list <B>function_info</B> <I>([str <VAR>name</VAR>])</I>
<DD><A NAME="IDX105"></A>
Returns descriptions of the built-in functions available on the server.  If
<VAR>name</VAR> is provided, only the description of the function with that name is
returned.  If <VAR>name</VAR> is omitted, a list of descriptions is returned, one
for each function available on the server.  Raised <CODE>E_INVARG</CODE> if
<VAR>name</VAR> is provided but no function with that name is available on the
server.

</P>
<P>
Each function description is a list of the following form:

</P>

<PRE>
{<VAR>name</VAR>, <VAR>min-args</VAR>, <VAR>max-args</VAR>, <VAR>types</VAR>
</PRE>

<P>
where <VAR>name</VAR> is the name of the built-in function, <VAR>min-args</VAR> is the
minimum number of arguments that must be provided to the function,
<VAR>max-args</VAR> is the maximum number of arguments that can be provided to the
function or <CODE>-1</CODE> if there is no maximum, and <VAR>types</VAR> is a list of
<VAR>max-args</VAR> integers (or <VAR>min-args</VAR> if <VAR>max-args</VAR> is <CODE>-1</CODE>),
each of which represents the type of argument required in the corresponding
position.  Each type number is as would be returned from the <CODE>typeof()</CODE>
built-in function except that <CODE>-1</CODE> indicates that any type of value is
acceptable and <CODE>-2</CODE> indicates that either integers or floating-point
numbers may be given.  For example, here are several entries from the list:

</P>

<PRE>
{"listdelete", 2, 2, {4, 0}}
{"suspend", 0, 1, {0}}
{"server_log", 1, 2, {2, -1}}
{"max", 1, -1, {-2}}
{"tostr", 0, -1, {}}
</PRE>

<P>
<CODE>Listdelete()</CODE> takes exactly 2 arguments, of which the first must be a
list (<CODE>LIST == 4</CODE>) and the second must be an integer (<CODE>INT == 0</CODE>).
<CODE>Suspend()</CODE> has one optional argument that, if provided, must be an
integer.  <CODE>Server_log()</CODE> has one required argument that must be a string
(<CODE>STR == 2</CODE>) and one optional argument that, if provided, may be of any
type.  <CODE>Max()</CODE> requires at least one argument but can take any number
above that, and the first argument must be either an integer or a
floating-point number; the type(s) required for any other arguments can't be
determined from this description.  Finally, <CODE>tostr()</CODE> takes any number of
arguments at all, but it can't be determined from this description which
argument types would be acceptable in which positions.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> list <B>eval</B> <I>(str <VAR>string</VAR>)</I>
<DD><A NAME="IDX106"></A>
The MOO-code compiler processes <VAR>string</VAR> as if it were to be the program
associated with some verb and, if no errors are found, that fictional verb is
invoked.  If the programmer is not, in fact, a programmer, then <CODE>E_PERM</CODE>
is raised.  The normal result of calling <CODE>eval()</CODE> is a two element list.
The first element is true if there were no compilation errors and false
otherwise.  The second element is either the result returned from the fictional
verb (if there were no compilation errors) or a list of the compiler's error
messages (otherwise).

</P>
<P>
When the fictional verb is invoked, the various built-in variables have values
as shown below:

</P>

<PRE>
player    the same as in the calling verb
this      #-1
caller    the same as the initial value of <CODE>this</CODE> in the calling verb

args      {}
argstr    ""

verb      ""
dobjstr   ""
dobj      #-1
prepstr   ""
iobjstr   ""
iobj      #-1
</PRE>

<P>
The fictional verb runs with the permissions of the programmer and as if its
<SAMP>`d'</SAMP> permissions bit were on.

</P>

<PRE>
eval("return 3 + 4;")   =>   {1, 7}
</PRE>

</DL>

<P>
<DL>
<DT><U>Function:</U> none <B>set_task_perms</B> <I>(obj <VAR>who</VAR>)</I>
<DD><A NAME="IDX107"></A>
Changes the permissions with which the currently-executing verb is running to
be those of <VAR>who</VAR>.  If the programmer is neither <VAR>who</VAR> nor a wizard,
then <CODE>E_PERM</CODE> is raised.

</P>

<BLOCKQUOTE>
<P>
<STRONG>Note</STRONG>: This does not change the owner of the currently-running verb,
only the permissions of this particular invocation.  It is used in verbs owned
by wizards to make themselves run with lesser (usually non-wizard) permissions.
</BLOCKQUOTE>

</DL>

<P>
<DL>
<DT><U>Function:</U> obj <B>caller_perms</B> <I>()</I>
<DD><A NAME="IDX108"></A>
Returns the permissions in use by the verb that called the currently-executing
verb.  If the currently-executing verb was not called by another verb (i.e., it
is the first verb called in a command or server task), then
<CODE>caller_perms()</CODE> returns <CODE>#-1</CODE>.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> int <B>ticks_left</B> <I>()</I>
<DD><A NAME="IDX109"></A>
<DT><U>Function:</U> int <B>seconds_left</B> <I>()</I>
<DD><A NAME="IDX110"></A>
These two functions return the number of ticks or seconds (respectively) left
to the current task before it will be forcibly terminated.  These are useful,
for example, in deciding when to call <SAMP>`suspend()'</SAMP> to continue a long-lived
computation.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> int <B>task_id</B> <I>()</I>
<DD><A NAME="IDX111"></A>
Returns the non-zero, non-negative integer identifier for the
currently-executing task.  Such integers are randomly selected for each task and
can therefore safely be used in circumstances where unpredictability is
required.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> value <B>suspend</B> <I>([int <VAR>seconds</VAR>])</I>
<DD><A NAME="IDX112"></A>
Suspends the current task, and resumes it after at least <VAR>seconds</VAR> seconds.
(If <VAR>seconds</VAR> is not provided, the task is suspended indefinitely; such a
task can only be resumed by use of the <CODE>resume()</CODE> function.)  When the
task is resumed, it will have a full quota of ticks and seconds.  This function
is useful for programs that run for a long time or require a lot of ticks.  If
<VAR>seconds</VAR> is negative, then <CODE>E_INVARG</CODE> is raised.  <CODE>Suspend()</CODE>
returns zero unless it was resumed via <CODE>resume()</CODE>, in which case it
returns the second argument given to that function.

</P>
<P>
In some sense, this function forks the `rest' of the executing task.  However,
there is a major difference between the use of <SAMP>`suspend(<VAR>seconds</VAR>)'</SAMP>
and the use of the <SAMP>`fork (<VAR>seconds</VAR>)'</SAMP>.  The <SAMP>`fork'</SAMP> statement
creates a new task (a <STRONG>forked task</STRONG>) while the currently-running task still
goes on to completion, but a <CODE>suspend()</CODE> suspends the currently-running
task (thus making it into a <STRONG>suspended task</STRONG>).  This difference may be best
explained by the following examples, in which one verb calls another:

</P>

<PRE>
.program   #0:caller_A
#0.prop = 1;
#0:callee_A();
#0.prop = 2;
.

.program   #0:callee_A
fork(5)
  #0.prop = 3;
endfork
.

.program   #0:caller_B
#0.prop = 1;
#0:callee_B();
#0.prop = 2;
.

.program   #0:callee_B
suspend(5);
#0.prop = 3;
.
</PRE>

<P>
Consider <CODE>#0:caller_A</CODE>, which calls <CODE>#0:callee_A</CODE>.  Such a task would
assign 1 to <CODE>#0.prop</CODE>, call <CODE>#0:callee_A</CODE>, fork a new task, return to
<CODE>#0:caller_A</CODE>, and assign 2 to <CODE>#0.prop</CODE>, ending this task.  Five
seconds later, if the forked task had not been killed, then it would begin to
run; it would assign 3 to <CODE>#0.prop</CODE> and then stop.  So, the final value of
<CODE>#0.prop</CODE> (i.e., the value after more than 5 seconds) would be 3.

</P>
<P>
Now consider <CODE>#0:caller_B</CODE>, which calls <CODE>#0:callee_B</CODE> instead of
<CODE>#0:callee_A</CODE>.  This task would assign 1 to <CODE>#0.prop</CODE>, call
<CODE>#0:callee_B</CODE>, and suspend.  Five seconds later, if the suspended task had
not been killed, then it would resume; it would assign 3 to <CODE>#0.prop</CODE>,
return to <CODE>#0:caller_B</CODE>, and assign 2 to <CODE>#0.prop</CODE>, ending the task.
So, the final value of <CODE>#0.prop</CODE> (i.e., the value after more than 5
seconds) would be 2.

</P>
<P>
A suspended task, like a forked task, can be described by the
<CODE>queued_tasks()</CODE> function and killed by the <CODE>kill_task()</CODE> function.
Suspending a task does not change its task id.  A task can be suspended again
and again by successive calls to <CODE>suspend()</CODE>.

</P>
<P>
By default, there is no limit to the number of tasks any player may suspend,
but such a limit can be imposed from within the database.  See the chapter on
server assumptions about the database for details.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> none <B>resume</B> <I>(int <VAR>task-id</VAR> [, <VAR>value</VAR>])</I>
<DD><A NAME="IDX113"></A>
Immediately ends the suspension of the suspended task with the given
<VAR>task-id</VAR>; that task's call to <CODE>suspend()</CODE> will return <VAR>value</VAR>,
which defaults to zero.  <CODE>Resume()</CODE> raises <CODE>E_INVARG</CODE> if
<VAR>task-id</VAR> does not specify an existing suspended task and <CODE>E_PERM</CODE> if
the programmer is neither a wizard nor the owner of the specified task.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> list <B>queue_info</B> <I>([obj <VAR>player</VAR>])</I>
<DD><A NAME="IDX114"></A>
If <VAR>player</VAR> is omitted, returns a list of object numbers naming all players
that currently have active task queues inside the server.  If <VAR>player</VAR> is
provided, returns the number of background tasks currently queued for that
user.  It is guaranteed that <CODE>queue_info(<VAR>X</VAR>)</CODE> will return zero for
any <VAR>X</VAR> not in the result of <CODE>queue_info()</CODE>.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> list <B>queued_tasks</B> <I>()</I>
<DD><A NAME="IDX115"></A>
Returns information on each of the background tasks (i.e., forked, suspended or
reading) owned by the programmer (or, if the programmer is a wizard, all queued
tasks).  The returned value is a list of lists, each of which encodes certain
information about a particular queued task in the following format:

</P>

<PRE>
{<VAR>task-id</VAR>, <VAR>start-time</VAR>, <VAR>x</VAR>, <VAR>y</VAR>,
 <VAR>programmer</VAR>, <VAR>verb-loc</VAR>, <VAR>verb-name</VAR>, <VAR>line</VAR>, <VAR>this</VAR>}
</PRE>

<P>
where <VAR>task-id</VAR> is an integer identifier for this queued task,
<VAR>start-time</VAR> is the time after which this task will begin execution (in
<CODE>time()</CODE> format), <VAR>x</VAR> and <VAR>y</VAR> are obsolete values that are no
longer interesting, <VAR>programmer</VAR> is the permissions with which this task
will begin execution (and also the player who <STRONG>owns</STRONG> this task),
<VAR>verb-loc</VAR> is the object on which the verb that forked this task was
defined at the time, <VAR>verb-name</VAR> is that name of that verb, <VAR>line</VAR> is
the number of the first line of the code in that verb that this task will
execute, and <VAR>this</VAR> is the value of the variable <SAMP>`this'</SAMP> in that verb.
For reading tasks, <VAR>start-time</VAR> is <CODE>-1</CODE>.

</P>
<P>
The <VAR>x</VAR> and <VAR>y</VAR> fields are now obsolete and are retained only for
backward-compatibility reasons.  They may be reused for new purposes in some
future version of the server.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> none <B>kill_task</B> <I>(int <VAR>task-id</VAR>)</I>
<DD><A NAME="IDX116"></A>
Removes the task with the given <VAR>task-id</VAR> from the queue of waiting tasks.
If the programmer is not the owner of that task and not a wizard, then
<CODE>E_PERM</CODE> is raised.  If there is no task on the queue with the given
<VAR>task-id</VAR>, then <CODE>E_INVARG</CODE> is raised.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> list <B>callers</B> <I>([<VAR>include-line-numbers</VAR>])</I>
<DD><A NAME="IDX117"></A>
Returns information on each of the verbs and built-in functions currently
waiting to resume execution in the current task.  When one verb or function
calls another verb or function, execution of the caller is temporarily
suspended, pending the called verb or function returning a value.  At any given
time, there could be several such pending verbs and functions: the one that
called the currently executing verb, the verb or function that called that one,
and so on.  The result of <CODE>callers()</CODE> is a list, each element of which
gives information about one pending verb or function in the following format:

</P>

<PRE>
{<VAR>this</VAR>, <VAR>verb-name</VAR>, <VAR>programmer</VAR>, <VAR>verb-loc</VAR>, <VAR>player</VAR>, <VAR>line-number</VAR>}
</PRE>

<P>
For verbs, <VAR>this</VAR> is the initial value of the variable <SAMP>`this'</SAMP> in that
verb, <VAR>verb-name</VAR> is the name used to invoke that verb, <VAR>programmer</VAR> is
the player with whose permissions that verb is running, <VAR>verb-loc</VAR> is the
object on which that verb is defined, <VAR>player</VAR> is the initial value of the
variable <SAMP>`player'</SAMP> in that verb, and <VAR>line-number</VAR> indicates which line
of the verb's code is executing.  The <VAR>line-number</VAR> element is included
only if the <VAR>include-line-numbers</VAR> argument was provided and true.

</P>
<P>
For functions, <VAR>this</VAR>, <VAR>programmer</VAR>, and <VAR>verb-loc</VAR> are all
<CODE>#-1</CODE>, <VAR>verb-name</VAR> is the name of the function, and <VAR>line-number</VAR>
is an index used internally to determine the current state of the built-in
function.  The simplest correct test for a built-in function entry is

</P>

<PRE>
(VERB-LOC == #-1  &#38;&#38;  PROGRAMMER == #-1  &#38;&#38;  VERB-NAME != "")
</PRE>

<P>
The first element of the list returned by <CODE>callers()</CODE> gives information on
the verb that called the currently-executing verb, the second element describes
the verb that called that one, and so on.  The last element of the list
describes the first verb called in this task.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> list <B>task_stack</B> <I>(int <VAR>task-id</VAR> [, <VAR>include-line-numbers</VAR>])</I>
<DD><A NAME="IDX118"></A>
Returns information like that returned by the <CODE>callers()</CODE> function, but
for the suspended task with the given <VAR>task-id</VAR>; the
<VAR>include-line-numbers</VAR> argument has the same meaning as in
<CODE>callers()</CODE>.  Raises <CODE>E_INVARG</CODE> if <VAR>task-id</VAR> does not specify an
existing suspended task and <CODE>E_PERM</CODE> if the programmer is neither a wizard
nor the owner of the specified task.
</DL>

</P>


<H3><A NAME="SEC55" HREF="ProgrammersManual_toc.html#SEC55">Administrative Operations</A></H3>

<P>
<DL>
<DT><U>Function:</U> str <B>server_version</B> <I>()</I>
<DD><A NAME="IDX119"></A>
Returns a string giving the version number of the running MOO server.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> none <B>server_log</B> <I>(str <VAR>message</VAR> [, <VAR>is-error</VAR>])</I>
<DD><A NAME="IDX120"></A>
The text in <VAR>message</VAR> is sent to the server log with a distinctive prefix
(so that it can be distinguished from server-generated messages).  If the
programmer is not a wizard, then <CODE>E_PERM</CODE> is raised.  If <VAR>is-error</VAR>
is provided and true, then <VAR>message</VAR> is marked in the server log as an
error.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> obj <B>renumber</B> <I>(obj <VAR>object</VAR>)</I>
<DD><A NAME="IDX121"></A>
The object number of the object currently numbered <VAR>object</VAR> is changed to
be the least nonnegative object number not currently in use and the new object
number is returned.  If <VAR>object</VAR> is not valid, then <CODE>E_INVARG</CODE> is
raised.  If the programmer is not a wizard, then <CODE>E_PERM</CODE> is raised.
If there are no unused nonnegative object numbers less than <VAR>object</VAR>, then
<VAR>object</VAR> is returned and no changes take place.

</P>
<P>
The references to <VAR>object</VAR> in the parent/children and location/contents
hierarchies are updated to use the new object number, and any verbs, properties
and/or objects owned by <VAR>object</VAR> are also changed to be owned by the new
object number.  The latter operation can be quite time consuming if the
database is large.  No other changes to the database are performed; in
particular, no object references in property values or verb code are updated.

</P>
<P>
This operation is intended for use in making new versions of the LambdaCore
database from the then-current LambdaMOO database, and other similar
situations.  Its use requires great care.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> none <B>reset_max_object</B> <I>()</I>
<DD><A NAME="IDX122"></A>
The server's idea of the highest object number ever used is changed to be the
highest object number of a currently-existing object, thus allowing reuse of
any higher numbers that refer to now-recycled objects.  If the programmer is
not a wizard, then <CODE>E_PERM</CODE> is raised.

</P>
<P>
This operation is intended for use in making new versions of the LambdaCore
database from the then-current LambdaMOO database, and other similar
situations.  Its use requires great care.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> list <B>memory_usage</B> <I>()</I>
<DD><A NAME="IDX123"></A>
On some versions of the server, this returns statistics concerning the server
consumption of system memory.  The result is a list of lists, each in the
following format:

</P>

<PRE>
{<VAR>block-size</VAR>, <VAR>nused</VAR>, <VAR>nfree</VAR>}
</PRE>

<P>
where <VAR>block-size</VAR> is the size in bytes of a particular class of memory
fragments, <VAR>nused</VAR> is the number of such fragments currently in use in the
server, and <VAR>nfree</VAR> is the number of such fragments that have been reserved
for use but are currently free.

</P>
<P>
On servers for which such statistics are not available, <CODE>memory_usage()</CODE>
returns <CODE>{}</CODE>.  The compilation option <CODE>USE_GNU_MALLOC</CODE> controls
whether or not statistics are available; if the option is not provided,
statistics are not available.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> none <B>dump_database</B> <I>()</I>
<DD><A NAME="IDX124"></A>
Requests that the server checkpoint the database at its next opportunity.  It
is not normally necessary to call this function; the server automatically
checkpoints the database at regular intervals; see the chapter on server
assumptions about the database for details.  If the programmer is not a wizard,
then <CODE>E_PERM</CODE> is raised.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> int <B>db_disk_size</B> <I>()</I>
<DD><A NAME="IDX125"></A>
Returns the total size, in bytes, of the most recent full representation of the
database as one or more disk files.  Raises <CODE>E_QUOTA</CODE> if, for some reason,
no such on-disk representation is currently available.
</DL>

</P>
<P>
<DL>
<DT><U>Function:</U> none <B>shutdown</B> <I>([str <VAR>message</VAR>])</I>
<DD><A NAME="IDX126"></A>
Requests that the server shut itself down at its next opportunity.  Before
doing so, a notice (incorporating <VAR>message</VAR>, if provided) is printed to all
connected players.  If the programmer is not a wizard, then <CODE>E_PERM</CODE> is
raised.
</DL>

</P>


<H1><A NAME="SEC56" HREF="ProgrammersManual_toc.html#SEC56">Server Commands and Database Assumptions</A></H1>

<P>
This chapter describes all of the commands that are built into the server and
every property and verb in the database specifically accessed by the server.
Aside from what is listed here, no assumptions are made by the server
concerning the contents of the database.

</P>



<H2><A NAME="SEC57" HREF="ProgrammersManual_toc.html#SEC57">Built-in Commands</A></H2>

<P>
As was mentioned in the chapter on command parsing, there are five commands
whose interpretation is fixed by the server: <CODE>PREFIX</CODE>,
<CODE>OUTPUTPREFIX</CODE>, <CODE>SUFFIX</CODE>, <CODE>OUTPUTSUFFIX</CODE>, and <CODE>.program</CODE>.
The first four of these are intended for use by programs that connect to the
MOO, so-called `client' programs.  The <CODE>.program</CODE> command is used by
programmers to associate a MOO program with a particular verb.  The server can,
in addition, recognize a sixth special command on any or all connections, the
<STRONG>flush</STRONG> command.

</P>
<P>
The server also performs special processing on command lines that begin with
certain punctuation characters.

</P>
<P>
This section discusses these built-in pieces of the command-interpretation
process.

</P>



<H3><A NAME="SEC58" HREF="ProgrammersManual_toc.html#SEC58">Command-Output Delimiters</A></H3>

<P>
Every MOO network connection has associated with it two strings, the
<STRONG>output prefix</STRONG> and the <STRONG>output suffix</STRONG>.  Just before executing a
command typed on that connection, the server prints the output prefix, if any,
to the player.  Similarly, just after finishing the command, the output suffix,
if any, is printed to the player.  Initially, these strings are not defined, so
no extra printing takes place.

</P>
<P>
The <CODE>PREFIX</CODE> and <CODE>SUFFIX</CODE> commands are used to set and clear these
strings.  They have the following simple syntax:

</P>

<PRE>
PREFIX  <VAR>output-prefix</VAR>
SUFFIX  <VAR>output-suffix</VAR>
</PRE>

<P>
That is, all text after the command name and any following spaces is used as
the new value of the appropriate string.  If there is no non-blank text after
the command string, then the corresponding string is cleared.  For
compatibility with some general MUD client programs, the server also recognizes
<CODE>OUTPUTPREFIX</CODE> as a synonym for <CODE>PREFIX</CODE> and <CODE>OUTPUTSUFFIX</CODE> as a
synonym for <CODE>SUFFIX</CODE>.

</P>
<P>
These commands are intended for use by programs connected to the MOO, so that
they can issue MOO commands and reliably determine the beginning and end of the
resulting output.  For example, one editor-based client program sends this
sequence of commands on occasion:

</P>

<PRE>
PREFIX &#62;&#62;MOO-Prefix&#60;&#60;
SUFFIX &#62;&#62;MOO-Suffix&#60;&#60;
@list <VAR>object</VAR>:<VAR>verb</VAR> without numbers
PREFIX
SUFFIX
</PRE>

<P>
The effect of which, in a LambdaCore-derived database, is to print out the code
for the named verb preceded by a line containing only <SAMP>`&#62;&#62;MOO-Prefix&#60;&#60;'</SAMP> and
followed by a line containing only <SAMP>`&#62;&#62;MOO-Suffix&#60;&#60;'</SAMP>.  This enables the
editor to reliably extract the program text from the MOO output and show it to
the user in a separate editor window.  There are many other possible uses.

</P>
<P>
The built-in function <CODE>output_delimiters()</CODE> can be used by MOO code to
find out the output prefix and suffix currently in effect on a particular
network connection.

</P>


<H3><A NAME="SEC59" HREF="ProgrammersManual_toc.html#SEC59">Programming</A></H3>

<P>
The <CODE>.program</CODE> command is a common way for programmers to associate a
particular MOO-code program with a particular verb.  It has the following
syntax:

</P>

<PRE>
.program <VAR>object</VAR>:<VAR>verb</VAR>
...<VAR>several lines of MOO code</VAR>...
.
</PRE>

<P>
That is, after typing the <CODE>.program</CODE> command, then all lines of input from
the player are considered to be a part of the MOO program being defined.  This
ends as soon as the player types a line containing only a dot (<SAMP>`.'</SAMP>).  When
that line is received, the accumulated MOO program is checked for proper MOO
syntax and, if correct, associated with the named verb.

</P>
<P>
If, at the time the line containing only a dot is processed, (a) the player is
not a programmer, (b) the player does not have write permission on the named
verb, or (c) the property <CODE>$server_options.protect_set_verb_code</CODE> exists
and has a true value and the player is not a wizard, then an error message is
printed and the named verb's program is not changed.

</P>
<P>
In the <CODE>.program</CODE> command, <VAR>object</VAR> may have one of three forms:

</P>

<UL>
<LI>

The name of some object visible to the player.  This is exactly like the kind
of matching done by the server for the direct and indirect objects of ordinary
commands.  See the chapter on command parsing for details.  Note that the
special names <SAMP>`me'</SAMP> and <SAMP>`here'</SAMP> may be used.

<LI>

An object number, in the form <CODE>#<VAR>number</VAR></CODE>.

<LI>

A <STRONG>system property</STRONG> (that is, a property on <CODE>#0</CODE>), in the form
<CODE>$<VAR>name</VAR></CODE>.  In this case, the current value of <CODE>#0.<VAR>name</VAR></CODE>
must be a valid object.
</UL>



<H3><A NAME="SEC60" HREF="ProgrammersManual_toc.html#SEC60">Flushing Unprocessed Input</A></H3>

<P>
It sometimes happens that a user changes their mind about having typed one or
more lines of input and would like to `untype' them before the server actually
gets around to processing them.  If they react quickly enough, they can type
their connection's defined <STRONG>flush</STRONG> command; when the server first reads
that command from the network, it immediately and completely flushes any as-yet
unprocessed input from that user, printing a message to the user describing
just which lines of input were discarded, if any.

</P>

<BLOCKQUOTE>
<P>
<EM>Fine point:</EM> The flush command is handled very early in the server's
processing of a line of input, before the line is entered into the task queue
for the connection and well before it is parsed into words like other commands.
For this reason, it must be typed exactly as it was defined, alone on the line,
without quotation marks, and without any spaces before or after it.
</BLOCKQUOTE>

<P>
When a connection is first accepted by the server, it is given an initial flush
command setting taken from the current default.  This initial setting can be
changed later using the <CODE>set_connection_option()</CODE> command.

</P>
<P>
By default, each connection is initially given <SAMP>`.flush'</SAMP> as its flush
command.  If the property <CODE>$server_options.default_flush_command</CODE> exists,
then its value overrides this default.  If
<CODE>$server_options.default_flush_command</CODE> is a non-empty string, then that
string is the flush command for all new connections; otherwise, new connections
are initially given no flush command at all.

</P>


<H3><A NAME="SEC61" HREF="ProgrammersManual_toc.html#SEC61">Initial Punctuation in Commands</A></H3>

<P>
The server interprets command lines that begin with any of the following
characters specially:

</P>

<PRE>
"        :        ;
</PRE>

<P>
Before processing the command, the initial punctuation character is replaced by
the corresponding word below, followed by a space:

</P>

<PRE>
say      emote    eval
</PRE>

<P>
For example, the command line

</P>

<PRE>
"Hello, there.
</PRE>

<P>
is transformed into

</P>

<PRE>
say Hello, there.
</PRE>

<P>
before parsing.

</P>


<H2><A NAME="SEC62" HREF="ProgrammersManual_toc.html#SEC62">Server Assumptions About the Database</A></H2>

<P>
There are a small number of circumstances under which the server directly and
specifically accesses a particular verb or property in the database.  This
section gives a complete list of such circumstances.

</P>



<H3><A NAME="SEC63" HREF="ProgrammersManual_toc.html#SEC63">Server Options Set in the Database</A></H3>

<P>
Many optional behaviors of the server can be controlled from within the
database by creating the property <CODE>#0.server_options</CODE> (also known as
<CODE>$server_options</CODE>), assigning as its value a valid object number, and then
defining various properties on that object.  At a number of times, the server
checks for whether the property <CODE>$server_options</CODE> exists and has an object
number as its value.  If so, then the server looks for a variety of other
properties on that <CODE>$server_options</CODE> object and, if they exist, uses their
values to control how the server operates.

</P>
<P>
The specific properties searched for are each described in the appropriate
section below, but here is a brief list of all of the relevant properties for
ease of reference:

</P>
<DL COMPACT>

<DT><CODE>bg_seconds</CODE>
<DD>
The number of seconds allotted to background tasks.
<DT><CODE>bg_ticks</CODE>
<DD>
The number of ticks allotted to background tasks.
<DT><CODE>connect_timeout</CODE>
<DD>
The maximum number of seconds to allow an un-logged-in in-bound connection to
remain open.
<DT><CODE>default_flush_command</CODE>
<DD>
The initial setting of each new connection's flush command.
<DT><CODE>fg_seconds</CODE>
<DD>
The number of seconds allotted to foreground tasks.
<DT><CODE>fg_ticks</CODE>
<DD>
The number of ticks allotted to foreground tasks.
<DT><CODE>max_stack_depth</CODE>
<DD>
The maximum number of levels of nested verb calls.
<DT><CODE>name_lookup_timeout</CODE>
<DD>
The maximum number of seconds to wait for a network hostname/address lookup.
<DT><CODE>outbound_connect_timeout</CODE>
<DD>
The maximum number of seconds to wait for an outbound network connection to
successfully open.
<DT><CODE>protect_<VAR>property</VAR></CODE>
<DD>
Restrict reading of built-in <VAR>property</VAR> to wizards.
<DT><CODE>protect_<VAR>function</VAR></CODE>
<DD>
Restrict use of built-in <VAR>function</VAR> to wizards.
<DT><CODE>support_numeric_verbname_strings</CODE>
<DD>
Enables use of an obsolete verb-naming mechanism.
</DL>



<H3><A NAME="SEC64" HREF="ProgrammersManual_toc.html#SEC64">Server Messages Set in the Database</A></H3>

<P>
There are a number of circumstances under which the server itself generates
messages on network connections.  Most of these can be customized or even
eliminated from within the database.  In each such case, a property on
<CODE>$server_options</CODE> is checked at the time the message would be printed.  If
the property does not exist, a default message is printed.  If the property
exists and its value is not a string or a list containing strings, then no
message is printed at all.  Otherwise, the string(s) are printed in place of
the default message, one string per line.  None of these messages are ever
printed on an outbound network connection created by the function
<CODE>open_network_connection()</CODE>.

</P>
<P>
The following list covers all of the customizable messages, showing for each
the name of the relevant property on <CODE>$server_options</CODE>, the default
message, and the circumstances under which the message is printed:

</P>
<DL COMPACT>

<DT><CODE>boot_msg = "*** Disconnected ***"</CODE>
<DD>
The function <CODE>boot_player()</CODE> was called on this connection.

<DT><CODE>connect_msg = "*** Connected ***"</CODE>
<DD>
The user object that just logged in on this connection existed before
<CODE>$do_login_command()</CODE> was called.

<DT><CODE>create_msg = "*** Created ***"</CODE>
<DD>
The user object that just logged in on this connection did not exist before
<CODE>$do_login_command()</CODE> was called.

<DT><CODE>recycle_msg = "*** Recycled ***"</CODE>
<DD>
The logged-in user of this connection has been recycled or renumbered (via the
renumber() function).

<DT><CODE>redirect_from_msg = "*** Redirecting connection to new port ***"</CODE>
<DD>
The logged-in user of this connection has just logged in on some other
connection.

<DT><CODE>redirect_to_msg = "*** Redirecting old connection to this port ***"</CODE>
<DD>
The user who just logged in on this connection was already logged in on some
other connection.

<DT><CODE>server_full_msg</CODE>
<DD>
Default:

<PRE>
*** Sorry, but the server cannot accept any more connections right now.
*** Please try again later.
</PRE>

This connection arrived when the server really couldn't accept any more
connections, due to running out of a critical operating system resource.

<DT><CODE>timeout_msg = "*** Timed-out waiting for login. ***"</CODE>
<DD>
This in-bound network connection was idle and un-logged-in for at least
<CODE>CONNECT_TIMEOUT</CODE> seconds (as defined in the file <SAMP>`options.h'</SAMP> when
the server was compiled).
</DL>


<BLOCKQUOTE>
<P>
<EM>Fine point:</EM> If the network connection in question was received at a
listening point (established by the <SAMP>`listen()'</SAMP> function) handled by an
object <VAR>obj</VAR> other than <CODE>#0</CODE>, then system messages for that connection
are looked for on <CODE><VAR>obj</VAR>.server_options</CODE>; if that property does not
exist, then <CODE>$server_options</CODE> is used instead.
</BLOCKQUOTE>



<H3><A NAME="SEC65" HREF="ProgrammersManual_toc.html#SEC65">Checkpointing the Database</A></H3>

<P>
The server maintains the entire MOO database in main memory, not on disk.  It
is therefore necessary for it to dump the database to disk if it is to persist
beyond the lifetime of any particular server execution.  The server is careful
to dump the database just before shutting down, of course, but it is also
prudent for it to do so at regular intervals, just in case something untoward
happens.

</P>
<P>
To determine how often to make these <STRONG>checkpoints</STRONG> of the database, the
server consults the value of <CODE>#0.dump_interval</CODE>.  If it exists and its
value is an integer greater than or equal to 60, then it is taken as the number
of seconds to wait between checkpoints; otherwise, the server makes a new
checkpoint every 3600 seconds (one hour).  If the value of
<CODE>#0.dump_interval</CODE> implies that the next checkpoint should be scheduled at
a time after 3:14:07 a.m. on Tuesday, January 19, 2038, then the server instead
uses the default value of 3600 seconds in the future.

</P>
<P>
The decision about how long to wait between checkpoints is made again
immediately after each one begins.  Thus, changes to <CODE>#0.dump_interval</CODE>
will take effect after the next checkpoint happens.

</P>
<P>
Whenever the server begins to make a checkpoint, it makes the following verb
call:

</P>

<PRE>
$checkpoint_started()
</PRE>

<P>
When the checkpointing process is complete, the server makes the following verb
call:

</P>

<PRE>
$checkpoint_finished(<VAR>success</VAR>)
</PRE>

<P>
where <VAR>success</VAR> is true if and only if the checkpoint was successfully
written on the disk.  Checkpointing can fail for a number of reasons, usually
due to exhaustion of various operating system resources such as virtual memory
or disk space.  It is not an error if either of these verbs does not exist; the
corresponding call is simply skipped.

</P>


<H3><A NAME="SEC66" HREF="ProgrammersManual_toc.html#SEC66">Accepting and Initiating Network Connections</A></H3>

<P>
When the server first accepts a new, incoming network connection, it is given
the low-level network address of computer on the other end.  It immediately
attempts to convert this address into the human-readable host name that will be
entered in the server log and returned by the <CODE>connection_name()</CODE>
function.  This conversion can, for the TCP/IP networking configurations,
involve a certain amount of communication with remote name servers, which can
take quite a long time and/or fail entirely.  While the server is doing this
conversion, it is not doing anything else at all; in particular, it it not
responding to user commands or executing MOO tasks.

</P>
<P>
By default, the server will wait no more than 5 seconds for such a name lookup
to succeed; after that, it behaves as if the conversion had failed, using
instead a printable representation of the low-level address.  If the property
<CODE>name_lookup_timeout</CODE> exists on <CODE>$server_options</CODE> and has an integer
as its value, that integer is used instead as the timeout interval.

</P>
<P>
When the <CODE>open_network_connection()</CODE> function is used, the server must
again do a conversion, this time from the host name given as an argument into
the low-level address necessary for actually opening the connection.  This
conversion is subject to the same timeout as in the in-bound case; if the
conversion does not succeed before the timeout expires, the connection attempt
is aborted and <CODE>open_network_connection()</CODE> raises <CODE>E_QUOTA</CODE>.

</P>
<P>
After a successful conversion, though, the server must still wait for the
actual connection to be accepted by the remote computer.  As before, this can
take a long time during which the server is again doing nothing else.  Also as
before, the server will by default wait no more than 5 seconds for the
connection attempt to succeed; if the timeout expires,
<CODE>open_network_connection()</CODE> again raises <CODE>E_QUOTA</CODE>.  This default
timeout interval can also be overridden from within the database, by defining
the property <CODE>outbound_connect_timeout</CODE> on <CODE>$server_options</CODE> with an
integer as its value.

</P>


<H3><A NAME="SEC67" HREF="ProgrammersManual_toc.html#SEC67">Associating Network Connections with Players</A></H3>

<P>
When a network connection is first made to the MOO, it is identified by a
unique, negative object number.  Such a connection is said to be
<STRONG>un-logged-in</STRONG> and is not yet associated with any MOO player object.

</P>
<P>
Each line of input on an un-logged-in connection is first parsed into words in
the usual way (see the chapter on command parsing for details) and then these
words are passed as the arguments in a call to the verb
<CODE>$do_login_command()</CODE>.  For example, the input line

</P>

<PRE>
connect Munchkin frebblebit
</PRE>

<P>
would result in the following call being made:

</P>

<PRE>
$do_login_command("connect", "Munchkin", "frebblebit")
</PRE>

<P>
In that call, the variable <CODE>player</CODE> will have as its value the negative
object number associated with the appropriate network connection.  The
functions <CODE>notify()</CODE> and <CODE>boot_player()</CODE> can be used with such object
numbers to send output to and disconnect un-logged-in connections.  Also, the
variable <CODE>argstr</CODE> will have as its value the unparsed command line as
received on the network connection.

</P>
<P>
If <CODE>$do_login_command()</CODE> returns a valid player object and the connection
is still open, then the connection is considered to have <STRONG>logged into</STRONG> that
player.  The server then makes one of the following verbs calls, depending on
the player object that was returned:

</P>

<PRE>
$user_created(<VAR>player</VAR>)
$user_connected(<VAR>player</VAR>)
$user_reconnected(<VAR>player</VAR>)
</PRE>

<P>
The first of these is used if the returned object number is greater than the
value returned by the <CODE>max_object()</CODE> function before
<CODE>$do_login_command()</CODE> was invoked, that is, it is called if the returned
object appears to have been freshly created.  If this is not the case, then one
of the other two verb calls is used.  The <CODE>$user_connected()</CODE> call is used
if there was no existing active connection for the returned player object.
Otherwise, the <CODE>$user_reconnected()</CODE> call is used instead.

</P>

<BLOCKQUOTE>
<P>
<EM>Fine point:</EM> If a user reconnects and the user's old and new connections
are on two different listening points being handled by different objects (see
the description of the <CODE>listen()</CODE> function for more details), then
<CODE>user_client_disconnected</CODE> is called for the old connection and
<CODE>user_connected</CODE> for the new one.
</BLOCKQUOTE>

<P>
If an in-bound network connection does not successfully log in within a certain
period of time, the server will automatically shut down the connection, thereby
freeing up the resources associated with maintaining it.  Let <VAR>L</VAR> be the
object handling the listening point on which the connection was received (or
<CODE>#0</CODE> if the connection came in on the initial listening point).  To
discover the timeout period, the server checks on
<CODE><VAR>L</VAR>.server_options</CODE> or, if it doesn't exist, on
<CODE>$server_options</CODE> for a <CODE>connect_timeout</CODE> property.  If one is found
and its value is a positive integer, then that's the number of seconds the
server will use for the timeout period.  If the <CODE>connect_timeout</CODE> property
exists but its value isn't a positive integer, then there is no timeout at
all.  If the property doesn't exist, then the default timeout is 300 seconds.

</P>
<P>
When any network connection (even an un-logged-in or outbound one) is
terminated, by either the server or the client, then one of the following two
verb calls is made:

</P>

<PRE>
$user_disconnected(<VAR>player</VAR>)
$user_client_disconnected(<VAR>player</VAR>)
</PRE>

<P>
The first is used if the disconnection is due to actions taken by the server
(e.g., a use of the <CODE>boot_player()</CODE> function or the un-logged-in timeout
described above) and the second if the disconnection was initiated by the
client side.

</P>
<P>
It is not an error if any of these five verbs do not exist; the corresponding
call is simply skipped.

</P>

<BLOCKQUOTE>
<P>
<STRONG>Note</STRONG>: Only one network connection can be controlling a given player
object at a given time; should a second connection attempt to log in as that
player, the first connection is unceremoniously closed (and
<CODE>$user_reconnected()</CODE> called, as described above).  This makes it easy to
recover from various kinds of network problems that leave connections open but
inaccessible.
</BLOCKQUOTE>

<P>
When the network connection is first established, the null command is
automatically entered by the server, resulting in an initial call to
<CODE>$do_login_command()</CODE> with no arguments.  This signal can be used by the
verb to print out a welcome message, for example.

</P>

<BLOCKQUOTE>
<P>
<STRONG>Warning</STRONG>: If there is no <CODE>$do_login_command()</CODE> verb defined, then
lines of input from un-logged-in connections are simply discarded.  Thus, it is
<EM>necessary</EM> for any database to include a suitable definition for this
verb.
</BLOCKQUOTE>



<H3><A NAME="SEC68" HREF="ProgrammersManual_toc.html#SEC68">Out-of-Band Commands</A></H3>

<P>
It is possible to compile the server with an option defining an
<STRONG>out-of-band prefix</STRONG> for commands.  This is a string that the server will
check for at the beginning of every line of input from players, regardless of
whether or not those players are logged in and regardless of whether or not
reading tasks are waiting for input from those players.  If a given line of
input begins with the defined out-of-band prefix (leading spaces, if any, are
<EM>not</EM> stripped before testing), then it is not treated as a normal command
or as input to any reading task.  Instead, the line is parsed into a list of
words in the usual way and those words are given as the arguments in a call to
<CODE>$do_out_of_band_command()</CODE>.  For example, if the out-of-band prefix were
defined to be <SAMP>`#$#'</SAMP>, then the line of input

</P>

<PRE>
#$# client-type fancy
</PRE>

<P>
would result in the following call being made in a new server task:

</P>

<PRE>
$do_out_of_band_command("#$#", "client-type", "fancy")
</PRE>

<P>
During the call to <CODE>$do_out_of_band_command()</CODE>, the variable <CODE>player</CODE>
is set to the object number representing the player associated with the
connection from which the input line came.  Of course, if that connection has
not yet logged in, the object number will be negative.  Also, the variable
<CODE>argstr</CODE> will have as its value the unparsed input line as received on the
network connection.

</P>
<P>
Out-of-band commands are intended for use by fancy client programs that may
generate asynchronous <STRONG>events</STRONG> of which the server must be notified.  Since
the client cannot, in general, know the state of the player's connection
(logged-in or not, reading task or not), out-of-band commands provide the only
reliable client-to-server communications channel.

</P>


<H3><A NAME="SEC69" HREF="ProgrammersManual_toc.html#SEC69">The First Tasks Run By the Server</A></H3>

<P>
Whenever the server is booted, there are a few tasks it runs right at the
beginning, before accepting connections or getting the value of
<CODE>#0.dump_interval</CODE> to schedule the first checkpoint (see below for more
information on checkpoint scheduling).

</P>
<P>
First, the server calls <CODE>$user_disconnected()</CODE> once for each user who
was connected at the time the database file was written; this allows for any
cleaning up that's usually done when users disconnect (e.g., moving their
player objects back to some `home' location, etc.).

</P>
<P>
Next, it checks for the existence of the verb <CODE>$server_started()</CODE>.  If
there is such a verb, then the server runs a task invoking that verb with no
arguments and with <CODE>player</CODE> equal to <CODE>#-1</CODE>.  This is useful for
carefully scheduling checkpoints and for re-initializing any state that is not
properly represented in the database file (e.g., re-opening certain outbound
network connections, clearing out certain tables, etc.).

</P>


<H3><A NAME="SEC70" HREF="ProgrammersManual_toc.html#SEC70">Controlling the Execution of Tasks</A></H3>

<P>
As described earlier, in the section describing MOO tasks, the server places
limits on the number of seconds for which any task may run continuously and the
number of "ticks," or low-level operations, any task may execute in one
unbroken period.  By default, foreground tasks may use 30,000 ticks and five
seconds, and background tasks may use 15,000 ticks and three seconds.  These
defaults can be overridden from within the database by defining any or all of
the following properties on <CODE>$server_options</CODE> and giving them integer
values:

</P>
<DL COMPACT>

<DT><CODE>bg_seconds</CODE>
<DD>
The number of seconds allotted to background tasks.
<DT><CODE>bg_ticks</CODE>
<DD>
The number of ticks allotted to background tasks.
<DT><CODE>fg_seconds</CODE>
<DD>
The number of seconds allotted to foreground tasks.
<DT><CODE>fg_ticks</CODE>
<DD>
The number of ticks allotted to foreground tasks.
</DL>

<P>
The server ignores the values of <CODE>fg_ticks</CODE> and <CODE>bg_ticks</CODE> if they
are less than 100 and similarly ignores <CODE>fg_seconds</CODE> and <CODE>bg_seconds</CODE>
if their values are less than 1.  This may help prevent utter disaster should
you accidentally give them uselessly-small values.

</P>
<P>
Recall that command tasks and server tasks are deemed <STRONG>foreground</STRONG> tasks,
while forked, suspended, and reading tasks are defined as <STRONG>background</STRONG>
tasks.  The settings of these variables take effect only at the beginning of
execution or upon resumption of execution after suspending or reading.

</P>
<P>
The server also places a limit on the number of levels of nested verb calls,
raising <CODE>E_MAXREC</CODE> from a verb-call expression if the limit is exceeded.
The limit is 50 levels by default, but this can be increased from within the
database by defining the <CODE>max_stack_depth</CODE> property on
<CODE>$server_options</CODE> and giving it an integer value greater than 50.  The
maximum stack depth for any task is set at the time that task is created and
cannot be changed thereafter.  This implies that suspended tasks, even after
being saved in and restored from the DB, are not affected by later changes to
$server_options.max_stack_depth.

</P>
<P>
Finally, the server can place a limit on the number of forked or suspended
tasks any player can have queued at a given time.  Each time a <CODE>fork</CODE>
statement or a call to <CODE>suspend()</CODE> is executed in some verb, the server
checks for a property named <CODE>queued_task_limit</CODE> on the programmer.  If
that property exists and its value is a non-negative integer, then that integer
is the limit.  Otherwise, if <CODE>$server_options.queued_task_limit</CODE> exists
and its value is a non-negative integer, then that's the limit.  Otherwise,
there is no limit.  If the programmer already has a number of queued tasks that
is greater than or equal to the limit, <CODE>E_QUOTA</CODE> is raised instead of
either forking or suspending.  Reading tasks are affected by the queued-task
limit.

</P>


<H3><A NAME="SEC71" HREF="ProgrammersManual_toc.html#SEC71">Controlling the Handling of Aborted Tasks</A></H3>

<P>
The server will abort the execution of tasks for either of two reasons:

<OL>
<LI>an error was raised within the task but not caught, or

<LI>the task exceeded the limits on ticks and/or seconds.

</OL>

<P>
In each case, after aborting the task, the server attempts to call a particular
<STRONG>handler verb</STRONG> within the database to allow code there to handle this
mishap in some appropriate way.  If this verb call suspends or returns a true
value, then it is considered to have handled the situation completely and no
further processing will be done by the server.  On the other hand, if the
handler verb does not exist, or if the call either returns a false value
without suspending or itself is aborted, the server takes matters into its own
hands.

</P>
<P>
First, an error message and a MOO verb-call stack <STRONG>traceback</STRONG> are
printed to the player who typed the command that created the original aborted
task, explaining why the task was aborted and where in the task the problem
occurred.  Then, if the call to the handler verb was itself aborted, a second
error message and traceback are printed, describing that problem as well.  Note
that if the handler-verb call itself is aborted, no further `nested' handler
calls are made; this policy prevents what might otherwise be quite a vicious
little cycle.

</P>
<P>
The specific handler verb, and the set of arguments it is passed, differs for
the two causes of aborted tasks.

</P>
<P>
If an error is raised and not caught, then the verb-call

<PRE>
$handle_uncaught_error(<VAR>code</VAR>, <VAR>msg</VAR>, <VAR>value</VAR>, <VAR>traceback</VAR>, <VAR>formatted</VAR>)
</PRE>

<P>
is made, where <VAR>code</VAR>, <VAR>msg</VAR>, <VAR>value</VAR>, and <VAR>traceback</VAR> are the
values that would have been passed to a handler in a <CODE>try</CODE>-<CODE>except</CODE>
statement and <VAR>formatted</VAR> is a list of strings being the lines of error and
traceback output that will be printed to the player if
<CODE>$handle_uncaught_error</CODE> returns false without suspending.

</P>
<P>
If a task runs out of ticks or seconds, then the verb-call

<PRE>
$handle_task_timeout(<VAR>resource</VAR>, <VAR>traceback</VAR>, <VAR>formatted</VAR>)
</PRE>

<P>
is made, where <VAR>resource</VAR> is the appropriate one of the strings
<CODE>"ticks"</CODE> or <CODE>"seconds"</CODE>, and <VAR>traceback</VAR> and <VAR>formatted</VAR> are
as above.

</P>


<H3><A NAME="SEC72" HREF="ProgrammersManual_toc.html#SEC72">Matching in Command Parsing</A></H3>

<P>
In the process of matching the direct and indirect object strings in a command
to actual objects, the server uses the value of the <CODE>aliases</CODE> property, if
any, on each object in the contents of the player and the player's location.
For complete details, see the chapter on command parsing.

</P>


<H3><A NAME="SEC73" HREF="ProgrammersManual_toc.html#SEC73">Restricting Access to Built-in Properties and Functions</A></H3>

<P>
Whenever verb code attempts to read the value of a built-in property <VAR>prop</VAR>
on any object, the server checks to see if the property
<CODE>$server_options.protect_<VAR>prop</VAR></CODE> exists and has a true value.  If so,
then <CODE>E_PERM</CODE> is raised if the programmer is not a wizard.

</P>
<P>
Whenever verb code calls a built-in function <CODE><VAR>func</VAR>()</CODE> and the caller
is not the object <CODE>#0</CODE>, the server checks to see if the property
<CODE>$server_options.protect_<VAR>func</VAR></CODE> exists and has a true value.  If so,
then the server next checks to see if the verb <CODE>$bf_<VAR>func</VAR>()</CODE> exists;
if that verb exists, then the server calls it <EM>instead</EM> of the built-in
function, returning or raising whatever that verb returns or raises.  If the
<CODE>$bf_<VAR>func</VAR>()</CODE> does not exist and the programmer is not a wizard, then
the server immediately raises <CODE>E_PERM</CODE>, <EM>without</EM> actually calling
the function.  Otherwise (if the caller is <CODE>#0</CODE>, if
<CODE>$server_options.protect_<VAR>func</VAR></CODE> either doesn't exist or has a false
value, or if <CODE>$bf_<VAR>func</VAR>()</CODE> exists but the programmer is a wizard),
then the built-in function is called normally.

</P>


<H3><A NAME="SEC74" HREF="ProgrammersManual_toc.html#SEC74">Creating and Recycling Objects</A></H3>

<P>
Whenever the <CODE>create()</CODE> function is used to create a new object, that
object's <CODE>initialize</CODE> verb, if any, is called with no arguments.  The call
is simply skipped if no such verb is defined on the object.

</P>
<P>
Symmetrically, just before the <CODE>recycle()</CODE> function actually destroys an
object, the object's <CODE>recycle</CODE> verb, if any, is called with no arguments.
Again, the call is simply skipped if no such verb is defined on the object.

</P>
<P>
Both <CODE>create()</CODE> and <CODE>recycle()</CODE> check for the existence of an
<CODE>ownership_quota</CODE> property on the owner of the newly-created or -destroyed
object.  If such a property exists and its value is an integer, then it is
treated as a <STRONG>quota</STRONG> on object ownership.  Otherwise, the following two
paragraphs do not apply.

</P>
<P>
The <CODE>create()</CODE> function checks whether or not the quota is positive; if
so, it is reduced by one and stored back into the <CODE>ownership_quota</CODE>
property on the owner.  If the quota is zero or negative, the quota is
considered to be exhausted and <CODE>create()</CODE> raises <CODE>E_QUOTA</CODE>.

</P>
<P>
The <CODE>recycle()</CODE> function increases the quota by one and stores it back
into the <CODE>ownership_quota</CODE> property on the owner.

</P>


<H3><A NAME="SEC75" HREF="ProgrammersManual_toc.html#SEC75">Object Movement</A></H3>

<P>
During evaluation of a call to the <CODE>move()</CODE> function, the server can make
calls on the <CODE>accept</CODE> and <CODE>enterfunc</CODE> verbs defined on the
destination of the move and on the <CODE>exitfunc</CODE> verb defined on the source.
The rules and circumstances are somewhat complicated and are given in detail in
the description of the <CODE>move()</CODE> function.

</P>


<H3><A NAME="SEC76" HREF="ProgrammersManual_toc.html#SEC76">Temporarily Enabling Obsolete Server Features</A></H3>

<P>
If the property <CODE>$server_options.support_numeric_verbname_strings</CODE> exists
and has a true value, then the server supports a obsolete mechanism for less
ambiguously referring to specific verbs in various built-in functions.  For
more details, see the discussion given just following the description of the
<CODE>verbs()</CODE> function.

</P>


<H1><A NAME="SEC77" HREF="ProgrammersManual_toc.html#SEC77">Function Index</A></H1>
<P>
<H2>a</H2>
<DIR>
<LI><A HREF="ProgrammersManual.html#IDX15">abs</A>
<LI><A HREF="ProgrammersManual.html#IDX22">acos</A>
<LI><A HREF="ProgrammersManual.html#IDX66">add_property</A>
<LI><A HREF="ProgrammersManual.html#IDX75">add_verb</A>
<LI><A HREF="ProgrammersManual.html#IDX21">asin</A>
<LI><A HREF="ProgrammersManual.html#IDX23">atan</A>
</DIR>
<H2>b</H2>
<DIR>
<LI><A HREF="ProgrammersManual.html#IDX45">binary_hash</A>
<LI><A HREF="ProgrammersManual.html#IDX92">boot_player</A>
<LI><A HREF="ProgrammersManual.html#IDX87">buffered_output_length</A>
</DIR>
<H2>c</H2>
<DIR>
<LI><A HREF="ProgrammersManual.html#IDX104">call_function</A>
<LI><A HREF="ProgrammersManual.html#IDX108">caller_perms</A>
<LI><A HREF="ProgrammersManual.html#IDX117">callers</A>
<LI><A HREF="ProgrammersManual.html#IDX30">ceil</A>
<LI><A HREF="ProgrammersManual.html#IDX58">children</A>
<LI><A HREF="ProgrammersManual.html#IDX55">chparent</A>
<LI><A HREF="ProgrammersManual.html#IDX69">clear_property</A>
<LI><A HREF="ProgrammersManual.html#IDX83">connected_players</A>
<LI><A HREF="ProgrammersManual.html#IDX84">connected_seconds</A>
<LI><A HREF="ProgrammersManual.html#IDX93">connection_name</A>
<LI><A HREF="ProgrammersManual.html#IDX96">connection_option</A>
<LI><A HREF="ProgrammersManual.html#IDX95">connection_options</A>
<LI><A HREF="ProgrammersManual.html#IDX19">cos</A>
<LI><A HREF="ProgrammersManual.html#IDX25">cosh</A>
<LI><A HREF="ProgrammersManual.html#IDX54">create</A>
<LI><A HREF="ProgrammersManual.html#IDX43">crypt</A>
<LI><A HREF="ProgrammersManual.html#IDX102">ctime</A>
</DIR>
<H2>d</H2>
<DIR>
<LI><A HREF="ProgrammersManual.html#IDX125">db_disk_size</A>
<LI><A HREF="ProgrammersManual.html#IDX38">decode_binary</A>
<LI><A HREF="ProgrammersManual.html#IDX67">delete_property</A>
<LI><A HREF="ProgrammersManual.html#IDX76">delete_verb</A>
<LI><A HREF="ProgrammersManual.html#IDX79">disassemble</A>
<LI><A HREF="ProgrammersManual.html#IDX124">dump_database</A>
</DIR>
<H2>e</H2>
<DIR>
<LI><A HREF="ProgrammersManual.html#IDX39">encode_binary</A>
<LI><A HREF="ProgrammersManual.html#IDX9">equal</A>
<LI><A HREF="ProgrammersManual.html#IDX106">eval</A>
<LI><A HREF="ProgrammersManual.html#IDX27">exp</A>
</DIR>
<H2>f</H2>
<DIR>
<LI><A HREF="ProgrammersManual.html#IDX16">floatstr(float</A>
<LI><A HREF="ProgrammersManual.html#IDX31">floor</A>
<LI><A HREF="ProgrammersManual.html#IDX90">flush_input</A>
<LI><A HREF="ProgrammersManual.html#IDX89">force_input</A>
<LI><A HREF="ProgrammersManual.html#IDX105">function_info</A>
</DIR>
<H2>i</H2>
<DIR>
<LI><A HREF="ProgrammersManual.html#IDX85">idle_seconds</A>
<LI><A HREF="ProgrammersManual.html#IDX35">index</A>
<LI><A HREF="ProgrammersManual.html#IDX68">is_clear_property</A>
<LI><A HREF="ProgrammersManual.html#IDX47">is_member</A>
<LI><A HREF="ProgrammersManual.html#IDX81">is_player</A>
</DIR>
<H2>k</H2>
<DIR>
<LI><A HREF="ProgrammersManual.html#IDX116">kill_task</A>
</DIR>
<H2>l</H2>
<DIR>
<LI><A HREF="ProgrammersManual.html#IDX33">length</A>, <A HREF="ProgrammersManual.html#IDX46">length</A>
<LI><A HREF="ProgrammersManual.html#IDX49">listappend</A>
<LI><A HREF="ProgrammersManual.html#IDX50">listdelete</A>
<LI><A HREF="ProgrammersManual.html#IDX98">listen</A>
<LI><A HREF="ProgrammersManual.html#IDX100">listeners</A>
<LI><A HREF="ProgrammersManual.html#IDX48">listinsert</A>
<LI><A HREF="ProgrammersManual.html#IDX51">listset</A>
<LI><A HREF="ProgrammersManual.html#IDX28">log</A>
<LI><A HREF="ProgrammersManual.html#IDX29">log10</A>
</DIR>
<H2>m</H2>
<DIR>
<LI><A HREF="ProgrammersManual.html#IDX40">match</A>
<LI><A HREF="ProgrammersManual.html#IDX14">max</A>
<LI><A HREF="ProgrammersManual.html#IDX61">max_object</A>
<LI><A HREF="ProgrammersManual.html#IDX123">memory_usage</A>
<LI><A HREF="ProgrammersManual.html#IDX13">min</A>
<LI><A HREF="ProgrammersManual.html#IDX62">move</A>
</DIR>
<H2>n</H2>
<DIR>
<LI><A HREF="ProgrammersManual.html#IDX86">notify</A>
</DIR>
<H2>o</H2>
<DIR>
<LI><A HREF="ProgrammersManual.html#IDX60">object_bytes</A>
<LI><A HREF="ProgrammersManual.html#IDX97">open_network_connection</A>
<LI><A HREF="ProgrammersManual.html#IDX91">output_delimiters</A>
</DIR>
<H2>p</H2>
<DIR>
<LI><A HREF="ProgrammersManual.html#IDX57">parent</A>
<LI><A HREF="ProgrammersManual.html#IDX1">pass</A>
<LI><A HREF="ProgrammersManual.html#IDX80">players</A>
<LI><A HREF="ProgrammersManual.html#IDX63">properties</A>
<LI><A HREF="ProgrammersManual.html#IDX64">property_info</A>
</DIR>
<H2>q</H2>
<DIR>
<LI><A HREF="ProgrammersManual.html#IDX114">queue_info</A>
<LI><A HREF="ProgrammersManual.html#IDX115">queued_tasks</A>
</DIR>
<H2>r</H2>
<DIR>
<LI><A HREF="ProgrammersManual.html#IDX103">raise</A>
<LI><A HREF="ProgrammersManual.html#IDX12">random</A>
<LI><A HREF="ProgrammersManual.html#IDX88">read</A>
<LI><A HREF="ProgrammersManual.html#IDX59">recycle</A>
<LI><A HREF="ProgrammersManual.html#IDX121">renumber</A>
<LI><A HREF="ProgrammersManual.html#IDX122">reset_max_object</A>
<LI><A HREF="ProgrammersManual.html#IDX113">resume</A>
<LI><A HREF="ProgrammersManual.html#IDX36">rindex</A>
<LI><A HREF="ProgrammersManual.html#IDX41">rmatch</A>
</DIR>
<H2>s</H2>
<DIR>
<LI><A HREF="ProgrammersManual.html#IDX110">seconds_left</A>
<LI><A HREF="ProgrammersManual.html#IDX120">server_log</A>
<LI><A HREF="ProgrammersManual.html#IDX119">server_version</A>
<LI><A HREF="ProgrammersManual.html#IDX94">set_connection_option</A>
<LI><A HREF="ProgrammersManual.html#IDX82">set_player_flag</A>
<LI><A HREF="ProgrammersManual.html#IDX65">set_property_info</A>
<LI><A HREF="ProgrammersManual.html#IDX107">set_task_perms</A>
<LI><A HREF="ProgrammersManual.html#IDX74">set_verb_args</A>
<LI><A HREF="ProgrammersManual.html#IDX78">set_verb_code</A>
<LI><A HREF="ProgrammersManual.html#IDX72">set_verb_info</A>
<LI><A HREF="ProgrammersManual.html#IDX52">setadd</A>
<LI><A HREF="ProgrammersManual.html#IDX53">setremove</A>
<LI><A HREF="ProgrammersManual.html#IDX126">shutdown</A>
<LI><A HREF="ProgrammersManual.html#IDX18">sin</A>
<LI><A HREF="ProgrammersManual.html#IDX24">sinh</A>
<LI><A HREF="ProgrammersManual.html#IDX17">sqrt</A>
<LI><A HREF="ProgrammersManual.html#IDX37">strcmp</A>
<LI><A HREF="ProgrammersManual.html#IDX44">string_hash</A>
<LI><A HREF="ProgrammersManual.html#IDX34">strsub</A>
<LI><A HREF="ProgrammersManual.html#IDX42">substitute</A>
<LI><A HREF="ProgrammersManual.html#IDX112">suspend</A>
</DIR>
<H2>t</H2>
<DIR>
<LI><A HREF="ProgrammersManual.html#IDX20">tan</A>
<LI><A HREF="ProgrammersManual.html#IDX26">tanh</A>
<LI><A HREF="ProgrammersManual.html#IDX111">task_id</A>
<LI><A HREF="ProgrammersManual.html#IDX118">task_stack</A>
<LI><A HREF="ProgrammersManual.html#IDX109">ticks_left</A>
<LI><A HREF="ProgrammersManual.html#IDX101">time</A>
<LI><A HREF="ProgrammersManual.html#IDX8">tofloat</A>
<LI><A HREF="ProgrammersManual.html#IDX5">toint</A>
<LI><A HREF="ProgrammersManual.html#IDX4">toliteral</A>
<LI><A HREF="ProgrammersManual.html#IDX6">tonum</A>
<LI><A HREF="ProgrammersManual.html#IDX7">toobj</A>
<LI><A HREF="ProgrammersManual.html#IDX3">tostr</A>
<LI><A HREF="ProgrammersManual.html#IDX32">trunc</A>
<LI><A HREF="ProgrammersManual.html#IDX2">typeof</A>
</DIR>
<H2>u</H2>
<DIR>
<LI><A HREF="ProgrammersManual.html#IDX99">unlisten</A>
</DIR>
<H2>v</H2>
<DIR>
<LI><A HREF="ProgrammersManual.html#IDX56">valid</A>
<LI><A HREF="ProgrammersManual.html#IDX10">value_bytes</A>
<LI><A HREF="ProgrammersManual.html#IDX11">value_hash</A>
<LI><A HREF="ProgrammersManual.html#IDX73">verb_args</A>
<LI><A HREF="ProgrammersManual.html#IDX77">verb_code</A>
<LI><A HREF="ProgrammersManual.html#IDX71">verb_info</A>
<LI><A HREF="ProgrammersManual.html#IDX70">verbs</A>
</DIR>

</P>

</BODY>
</HTML>