Previous: Built-In values, Up: Built-In


6.2 Functions

Enigma has few built-in functions. But they do exist.

str(OBJECT...): Converts all supplied values to strings.

num(OBJECT...): Converts all supplied values to numbers.

list(OBJECT...): Puts all supplied values in a list and destroys nested lists at one level.

bool(OBJECT...): Converts all supplied values to booleans.

code(OBJECT...): Converts all supplied values to code strings.

repr(OBJECT...): Converts all supplied values to representational strings. Strings get prepended and appended by " characters, code objects are surrounded by { and }, and so on.

type(OBJECT...): Converts all supplied values to type strings (string, number, file, etc.).

len(OBJECT...): Converts all supplied values to their length. This can be used for both strings and lists.

clone(OBJECT...): Clones all supplied values. When an object is cloned, its value is assigned to a new variable. The list of clones is returned.

slice(LIST|STRING, NUMBER, NUMBER): Returns a list value sliced according to the first and second number if the first variable is a list variable, or a substring if the first variable is a string variable.

loop(FUNCTION, [OBJECT]...): Executes function until it returns false. Sends the rest of the specified variables (if any) to the function as arguments.

open(STRING, STRING): Opens the file by the name of the first string, using the second string as its guide as to how it should be opened. "r" means to read, "w" means to write, and "a" means to append. Returns a file object.

close(FILE...): Closes files.

read(FILE): Reads one character of a file and returns it. If no more characters are present, an empty string is returned.

write(FILE, STRING): Writes a string to a file.

greater(NUMBER, NUMBER...: Checks if the first number is greater than the rest and returns true or false.

lesser(NUMBER, NUMBER...: Checks if the first number is lesser than the rest and returns true or false.

equal(OBJECT, OBJECT...: Checks if the objects are equal and returns true or false.

and(BOOLEAN...): Checks if all booleans are true and returns true or false.

or(BOOLEAN...): Checks if at least one boolean is true and returns true or false.

not(BOOLEAN...): Converts values of true to values of false, and vice-versa.

act(BOOLEAN, FUNCTION, [OBJECT]...): Run the function with the optional objects as arguments if the boolean is true.

system(STRING...): Join the strings and run the result as a system command.

add(NUMBER|STRING|CODE|LIST...): Add objects together. Numbers, strings, code strings and lists can be used, but only with similar types. The type of the first object determines what types the rest must be. The result is stored in the first object and also returned.

subtract(NUMBER...): Subtract numbers from each other. The first object receives the final number. It is also returned.

multiply(NUMBER...): Multiply numbers with each other. The first object receives the final number. It is also returned.

divide(NUMBER...): Divide numbers with each other. The first object receives the final number. It is also returned.

mod(NUMBER, NUMBER): Finds the remainder of the first number divided with the second number and returns it as a new variable.

pow(NUMBER, NUMBER): Returns first number^second number.

log(NUMBER, [NUMBER]): Returns the logarithm of the first number. If the second number is not specified, the natural logarith is used.

random(): Returns a random number between 0 and 1.

abs(NUMBER...): Sets and returns absolute values of numbers.

round(NUMBER, NUMBER): Rounds the first number with x decimals, where x is the second number.

floor(NUMBER, NUMBER): Floors the first number with x decimals, where x is the second number.

ceil(NUMBER, NUMBER): "Ceils" the first number with x decimals, where x is the second number.

sin(NUMBER...): Sets and returns sine values.

cos(NUMBER...): Sets and returns cosine values.

tan(NUMBER...): Sets and returns tangent values.

asin(NUMBER...): Sets and returns arcsine values.

acos(NUMBER...): Sets and returns arccosine values.

atan(NUMBER...): Sets and returns arctangent values.

sinh(NUMBER...): Sets and returns hyperbolic sine values.

cosh(NUMBER...): Sets and returns hyperbolic cosine values.

tanh(NUMBER...): Sets and returns hyperbolic tangent values.