Programming

First and foremost, the most important thing to realize about the LambdaMOO system is that there really isn't anything like a program to deal with. In C++, every program has a main function. For LambdaMOO, any implicit main program is safely concealed inside the internals of the system, and programmers have no say in the matter unless they wish to start hacking away at server code. For LambdaMOO, a programmer is restricted to constructing objects and their verbs. Like any object oriented system, a programmer could argue that the execution paths through the various verbs constitues a program, but unfortunately that argument tends to break down quickly since the entire point of having functions on an object is so that other objects can interact with each other. That's the point of object oriented programming.

Unless otherwise noted, when specifying commands for performing some action, any text enclosed in square brackets is optional. E.g. FunctionName(Arg1 [,Arg2) indicates that Arg2 is optional when calling the function Arg1.

Having said that, the next issue is how one constructs objects to do meaningful things in LambdaMOO. The major issues at this point are


Data Types in LambdaMOO
Data Typetypeof(...)==Conversion Function>Comments
IntegersINT or 0tonum(...) or toint(...)Signed whole numbers
ObjectOBJ or 1toobj(...)Reference number for an object
StringsSTR or 2tostr(...)String or character
ErrorERR or 3noneError condition. Used for various runtime errors
ListsLIST or 4noneImmutable list. Used for arrays and sets
Floating point numberFLOAT or 9tofloat(...)Signed floating point number
Creating Objects Creating properties on an object Needless to say, it is generally horribly complicated to add properties to objects from within a verb, and for most purposes there isn't really any need to. I'd personally recommend staying true to the rule of thumb that say "If you think you need to add a property to an object from within a verb you're probably wrong." To change the value (or type for that matter) of a property, the easiest way is simply to assign it a new value. Programmatically, this is simply
    ObjectReferece.Property = NewValue;
and to change a value at the command line, the only difference is to add a semicolon (to tell the command line interpreter that you are typing in an expression and not a command), like so:
;ObjectReference.Property = NewValue;
Creating verbs on an object Fun with lists and strings
Accessing and modifying elements of lists and strings

To access a particular element of a list or string, the square braces are used. Elements are numbered sequentially from 1 to n, where n is the length of the string or list.

Assigning to an element of a list or string modifies the corresponding element of the list or string.

For example:

    Test="George";	// Our example string
    Test[3]="4";	// Test is now "Ge4rge"
    Test[5..6]="56";    // Test is now "Ge456e"
    Test={"A","B","C"}; // Our example list
    Test[2]="BC";	// Test is now {"A","BC","C"};
    Test[2]="BC","DE";  // Error.  Invalid statement.
    Test[2]={"BC","DE"}; // Test is now {"A",{"BC","DE"},"C"};
As shown in the example, the elements selected from a list or string can be more than one element long. However, those elements have to be continuous. For example
    "George"[3..3]	// "o"
    "George"[3..5]	// "org"
    "George"[3..5,7..9] // syntax error
Strings can be costructed using the + operator to append two strings together. Unfortunately, this modifies neither of the two original strings.
    OriginalName="George";
    LastName=" The Great";
    NewName=OriginalName+LastName;
Changes neither OriginalName or LastName. There is absolutely nothing wrong with assigning like
    OriginalName="George";
    LastName=" The Great";
    OriginalName=OriginalName+LastName; // OriginalName = "George The Great"
    OriginalName="George"+LastName;     // Same result
    OriginalName="George"+" The Great"; // Same result
In fact, this way of appending to strings in absolutely necessary. In LambdaMOO (as in Java), a string is only as long as it absolutely has to be, and to append to a string (such as changing a string stored in a property) requires such a construct.

Lists are constructed in a similar manner. The ampersand operator, when applied to the front of a list name, expands out to the contents of that list. For example:

    List={1,2,3,4,5};
    List={@List};			// Identity operation
    List={@List,6};			// List = {1,2,3,4,5,6};
    Counter=1;
    while(Counter<6)
        List={@List,Counter};
        Counter=Counter+1;
    endwhile
    // List is now {1,2,3,4,5,6,1,2,3,4,5}
    NewList=List[7..10];		// NewList = {1,2,3}

The elements of a list can be lists themselves. There is no restriction on the layout of each sublist, and lists can be nested arbitrarily deep to construct multidimensional arrays or fancy data structures.

    List={};
    List={@List,{},{},{}};		// List now contains three empty lists.
    List[1]={1,2,{3,4,5,6}};		// The first list in List now contains
					// the list {1,2,{3,4,5,6}}
    List[3]=List[1];			// The third list in List now contains
					// a copy of List[1]
    List[3][3][2]=7;			// List is now
					// { {1,2,{3,4,5,6}}, {}, {1,2,{3,7,5,6}} }
For both lists, the in operator is very useful. in is a binary operator, the left argument being the element to look for, and the right element being the list to search. Its value is the position in its target to search, or 0 if the element is not found.
    (5 in {1,2,9,3,5,2}) 	// result is 5
    (4 in {0,4,4}		// result is 2
Like assignment, using in to look for substrings won't work. Likewise, if you construct a complicated list structure, in only checks the list and not any elements in the list.
    ({1,2} in {0,{1,2},{3,4}}) // result is 2
    (2 in {0,{1,2},{3,4}})     // result is 0

Various utility objects, such as $string_utils, $set_utils, $assoc_utils, $match_utils, and others are available for use. The specific documentation is available by @examineing the appropriate objects, or reading the comments in the verbs of the object.

The really important thing to remember is that if your were all set to use a binary tree, hash table, or other data structure normally implemented using pointers, you have two choices: 1--rethink the algorithm using lists, or 2--write, find or convince someone to write a set of functions to implement that data structure using LambdaMOO's lists.