/
html/
<HTML>
<HEAD>
<!-- This HTML file has been created by texi2html 1.51
     from ProgrammersManual.texinfo on 4 March 1997 -->

<TITLE>LambdaMOO Programmer's Manual - More On Lists</TITLE>
</HEAD>
<BODY>
Go to the <A HREF="ProgrammersManual_1.html">first</A>, <A HREF="ProgrammersManual_21.html">previous</A>, <A HREF="ProgrammersManual_23.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="SEC22" HREF="ProgrammersManual_toc.html#TOC22">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>
<P><HR><P>
Go to the <A HREF="ProgrammersManual_1.html">first</A>, <A HREF="ProgrammersManual_21.html">previous</A>, <A HREF="ProgrammersManual_23.html">next</A>, <A HREF="ProgrammersManual_77.html">last</A> section, <A HREF="ProgrammersManual_toc.html">table of contents</A>.
</BODY>
</HTML>