Extra Built-In Functions

Some special built-in functions have been added to LPMOO to facilitate the extra datatypes (floats and tables) as well as to improve the performance of the simulation.

Functions for Manipulating Floating Point Values

float tofloat(value)
Converts (almost) any MOO value into a floating point number.

float floor(float)
Rounds the argument towards negative infinity and returns the result.

float ceil(float)
Rounds the argument towards positive infinity and returns the result.

list frexp(float)
Splits the argument (x) into a fraction f and an integer exponent n, such that either f == 0.0, or 0.5 <= | f | < 1.0 and f * 2 ** n == x. {f, n} is returned. If the argument equals 0.0, both f and n will be zero.

float ldexp(float, num)
Adds an integer to the exponent of a float; float * 2 ** num is returned. This has the inverse effect of frexp().

list modf(float)
Splits the argument into a fraction f and an integer part n, such that | f | < 1.0, and f + n == x. {f, n} is returned. Note that n is returned as a float, and may not be representable as an integer.

Functions for Manipulating Table Values

table tablemap(list, list)
Creates and returns a new table built by associating each of the values from the first argument with the corresponding elements of the second argument. An error will result if the lists are not of the same size.

table tableinsert(table, key, value)
Returns a new table with {key ~ value} inserted (or altered.)

table tabledelete(table, key)
Returns a new table with the element associated with key removed.

list tablekeys(table)
Returns all of the keys present in the given table as a list.

list tablevalues(table)
Returns all of the values present in the given table as a list, in the same ordering that tablekeys() returns the keys for the same table.

num table_bound(table, key)
Returns 1 if and only if key is present the given table.

Miscellaneous Functions

string toliteral(value[, usequotes])
Returns a string representation for value, including recursive list or table elements. If usequotes is present and is false, string values will not be surrounded by quotation marks, and special characters within the string will not be escaped.

list fromliteral(string)
Returns {1, value} where value is the MOO value represented by the string argument. If the argument is malformed, {0, reason} is returned instead. This function assumes that strings have been properly escaped and are surrounded by quotation marks.

Modifications to Existing Functions

Some functions which already existed in version 1.7.7 of the LambdaMOO server have been enhanced to work with floats and tables.

Float arguments are converted into a simple string representation. Table arguments are converted into the string "{table}".

A float argument is rounded to the nearest integer. If the float value is so large that it cannot be represented as an integer, E_RANGE will be generated.

A float argument is rounded to the nearest integer, and then converted into an object value. The same range restriction applies as for tonum().

If a float argument is passed, the absolute value (also as a float) is returned.

If a float argument is passed, the floating point square root is returned.

If a table argument is passed, the number of elements in the table is returned.