<HTML> <HEAD> <!-- This HTML file has been created by texi2html 1.51 from ProgrammersManual.texinfo on 4 March 1997 --> <TITLE>LambdaMOO Programmer's Manual - Calling</TITLE> </HEAD> <BODY> Go to the <A HREF="ProgrammersManual_1.html">first</A>, <A HREF="ProgrammersManual_24.html">previous</A>, <A HREF="ProgrammersManual_26.html">next</A>, <A HREF="ProgrammersManual_77.html">last</A> section, <A HREF="ProgrammersManual_toc.html">table of contents</A>. <P><HR><P> <H3><A NAME="SEC25" HREF="ProgrammersManual_toc.html#TOC25">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> <P><HR><P> Go to the <A HREF="ProgrammersManual_1.html">first</A>, <A HREF="ProgrammersManual_24.html">previous</A>, <A HREF="ProgrammersManual_26.html">next</A>, <A HREF="ProgrammersManual_77.html">last</A> section, <A HREF="ProgrammersManual_toc.html">table of contents</A>. </BODY> </HTML>