LSLisp is a compact S-expression programming language meant to enable development of soft-coded scripting interfaces in Second Life. Despite its resemblance to the LISP programming language, LSLisp is best described as a simple, single-scope procedural language similar to FORTRAN. LSLisp does not yet support user-defined subroutines.

Like most other S-expression languages, LSLisp uses cell-based notation to represent code and data structures. This substantially simplifies the burden of parsing, at a slight cost to legibility. For example:

LSL: llOwnerSay("Hello, world.");
LSLisp: (print "Hello, world.")

In general, the formula for a statement is (<function> [<argument> [ ... ]]). Commas are not used to separate arguments, only spaces, and no line terminators are required. S-expression languages do not generally support infix operators, so even mathematical expressions as simple as 1 + 2 are rendered with a function instead; in LSLisp, this is (sum 1 2).

Here are some examples, comparing how to perform common tasks in LSL and LSLisp:

LSLLSLisp
integer a = 3;
integer b = 2;
b = a + b;
(set a 3)
(set b 2)
(set b $a $b)
if (a < b)
    llOwnerSay((string)a + " is less than " + (string)b + "!");
else
    llOwnerSay((string)a + " isn't less than " + (string)b + ".");
(if (lt $a $b)
    (print (concat "" (list $a " is less than " $b "!")))
    (print (concat "" (list $a " isn't less than " $b ".")))
)
integer j = (i * k) | ((b + c) & d); (set j (or (product $i $k) (and (sum $b $c) $d)))
// Comment
/* Multi-line comment */
(comments are not yet supported)
while (a < 10) {
    a += 1;
    b = a;
}
(while (lt $a 10) (
    (set a (sum $a 1))
    (set b $a)
))
list a = [1, 2, 3];
integer b = llList2Integer(a, 2); // sets b to 3
(set a (list 1 2 3))
(set b (get $a 2))

Careful review of the above LSLisp examples will reveal that certain references to variables start with $, and others do not. The rules for this are similar to shell scripting languages, such as bash: to insert the value of a variable into the code, use the $ sigil. To refer to the variable by name (only needed for set), use no sigil. Review the above examples again, and you will see clearly that the sigil is only missing from the first argument of set, which is the variable name to which we are assigning a value.

With the above analogies in mind, the following is a complete list of supported functions in LSLisp 0.1, the current release version:

functionexampleclosest LSL equivalentdescription
print(print $username " is here! How are you?")llRegionSayTo(user, 0, ...)Sends a message to the agent who activated the script on channel 0.
list(list 1 2 3)square bracketsCreates a list object, stored in JSON format. Recursive lists are supported.
set(set variable $value)=Sets the first argument to contain the value of the second. Note that no $ sigil precedes the destination variable.
sum(sum 5 100 3000) (Returns 3105.)+Adds the arguments and returns the result as a floating point number.
product(product 2 3 10) (Returns 60.)*Multiplies the arguments and returns the result as a floating point number.
eq(eq 1 2) (Returns 0.)==Checks for equality.
ne(ne 1 2) (Returns 1.)!=Checks for inequality.
lt(lt 1 2) (Returns 1.)<Checks if the first argument is less than the second.
gt(gt 1 2) (Returns 0.)>Checks if the first argument is greater than the second.
and(and 255 515) (Returns 3.)&Performs bitwise AND.
or(or 255 515) (Returns 767.)|Performs bitwise OR.
not(not 1)!Converts 0 to 1, and all other values to 0.
-(- $value)unary minusNegates a value.
concat(concat $sep $items)llDumpList2String(items, sep)Concatenates a list (the second argument) into a single string value, using the first argument as a separator.
split(split $sep $items)llParseString2List(text, [sep], [])Splits a string (the second argument) into a list using the first argument as a separator.
get(get $items $subscripts)llList2* functionsExtracts an element from a list. The first argument is the list, and the second is the index of the element. Both arguments are lists, as this function supports nested lists.
index(index $items $query)llListFindList(items, [query])Locates the first occurrence of the second argument within the first argument. Does not support multi-level lists, unlike put and get.
count(count $items)llGetListLength(items)Returns the number of elements in the argument.
put(put $items $subscripts $value)llListReplaceList(items, [value], subscript)Stores the third parameter in the first, at the position indicated by the second list. Note that the first and second arguments are lists, as this function supports nested lists.
char(char $text $index)llGetSubString(text, query, query)Returns a single character from a string.
substr(substr $text $start $end)llGetSubString(text, start, end)Returns the substring of $text starting at $start and ending at $end, inclusive. Supports LSL's negative indexing.
strpos(strpos $text $query)llSubStringIndex(text, query)Locates the first occurrence of $query within $text and returns its starting position.
rand(rand)llFrand(1)Generates a random floating point number between 0.0 and 1.0.
int(int 2.5)(integer)Casts the provided value into an integer. This can be used to discard a decimal fraction (always rounding toward 0) of a floating point number, or to parse a string into an integer.
if(if $value (...¹) (...²))if(value) { ...¹ } else { ...² }If $value is non-zero, executes (...¹). Otherwise, executes (...²). The (...²) branch may be omitted.
while(while $value (...))while(value) { ... }Evaluates value. If non-zero, executes the (...) block, and repeats the process.
external(external $number $parameters)llMessageLinked(LINK_ROOT, TASK_START | number, $parameters, interrupt=llGenerateKey())Pauses execution until another linked message is received, bearing the same key parameter. The string parameter of that response message is returned. Not currently supported inside if or while.
@name(@name $parameters)llMessageLinked(LINK_ROOT, TASK_START | EXECUTE, name + " " + parameters, user)(Companion only) Runs the specified system command with the supplied parameters. The "user" is the UUID of the agent or object supplied when LSLisp was invoked.
#number(#number $parameters)llMessageLinked(LINK_ROOT, TASK_START | number, parameters, user)(Companion only) Sends the specified linked message with the supplied parameters. The "user" is the UUID of the agent or object supplied when LSLisp was invoked.