Core library

Index:

Functions:

!=

!=

Synopsis
Test if arguments are different.
Usage
(!= value1 value2)
Returns
result
Where
  • value1 is object: the first value to compare.
  • value2 is object: the second value to compare.
  • result is boolean: true if not all arguments are equal, false otherwise.
Description
Returns true if its arguments are different, false otherwise.
Examples
(!= 4 5)
true
###

###

Synopsis
Comments a block of code.
Usage
(### param ... param)
Returns
null
Where
  • param is object[0..N]: commented code or a descriptive text.
Description
This function do not evaluates any of its arguments and always returns null. It can only be used inside functions that accept a null argument, like do, while, etc.
Examples
(do
  (### "This is a comment inside a do")
  (set counter 0)
)
(do
  (set i 0)
  (###
    (while (< i max_iter)
      (process_data i)
      (++ i)
    )
  )
  (show_results)
)
*

*

Synopsis
Multiplication of numbers.
Usage
(* value ... value)
Returns
result
Where
  • value is number[0..N]: a value to multiply.
  • result is number: the multiplication of the specified values or 1 if no arguments are provided.
Description
Returns the result of multiplicating the specified values.
Examples
(* 2 4 5)
40
Related functions
+

+

Synopsis
Sum of numbers.
Usage
(+ value ... value)
Returns
result
Where
  • value is number[0..N]: a value to add.
  • result is number: the sum of the specified values or 0 if no arguments are provided.
Description
Returns the result of adding the specified values.
Examples
(+ 1 2 8)
11
Related functions
++

++

Synopsis
Increments a variable.
Usage
(++ variable value)
Returns
result
Where
  • variable is reference: a reference to the variable to increment. This argument is not evaluated if it is already a reference.
  • value is number[0..1]: the value to increment the variable.
  • result is number: the variable value after incrementing it.
Description
Increments the given variable by the specified value. When value is omitted, variable is incremented by 1.
Examples
(do
  (set a 10)
  (++ a 2)
)
12
Related functions
-

-

Synopsis
Subtract two numbers.
Usage
(- value1 value2)
Returns
result
Where
  • value1 is number: the value to subtract from.
  • value2 is number[0..1]: the value to be subtracted.
  • result is number: the result of evaluating value1 - value2 or -value1 if value2 is omitted.
Description
When value2 is present, this function returns the result of subtracting value2 from value1. If value2 is omitted, -value1 is returned.
Examples
(- 10 2)
8
(- 5)
-5
Related functions
--

--

Synopsis
Decrements a variable.
Usage
(-- variable value)
Returns
result
Where
  • variable is reference: a reference to the variable to decrement. This argument is not evaluated if it is already a reference.
  • value is number[0..1]: the value to decrement the variable.
  • result is number: the variable value after decrementing it.
Description
Decrements the given variable by the specified value. When value is omitted, variable is decremented by 1.
Examples
(do
  (set a 10)
  (-- a 2)
)
8
Related functions
/

/

Synopsis
Divides 2 numbers.
Usage
(/ dividend divisor)
Returns
result
Where
  • dividend is number: the dividend of the division.
  • divisor is number: the divisor of the division.
  • result is number: a double that is the result of dividing dividend by divisor.
Description
Returns a double that is the result of dividing the specified numbers.
Examples
(/ 3 2)
1.5
Related functions
<

<

Synopsis
Test if one value is less than another.
Usage
(< value ... value)
Returns
result
Where
  • value is object[0..N]: a value to compare.
  • result is boolean: true if for each two consecutive arguments the first one is less than the second one. False otherwise.
Description
Returns true if for each two consecutive arguments the first one is less than the second one. Returns false otherwise.
Examples
(< 1 2 3)
true
<=

<=

Synopsis
Test if one value is less than or equal to another.
Usage
(<= value ... value)
Returns
result
Where
  • value is object[0..N]: a value to compare.
  • result is boolean: true if for each two consecutive arguments the first one is less than or equal to the second one. False otherwise.
Description
Returns true if for each two consecutive arguments the first one is less than or equal to the second one. Returns false otherwise.
Examples
(<= 1 2 2 3)
true
=

=

Synopsis
Test if arguments are equal ignoring list names.
Usage
(= value ... value)
Returns
result
Where
  • value is object[0..N]: a value to compare.
  • result is boolean: true if all arguments are equal, false otherwise.
Description
Returns true if all arguments are equal, false otherwise. When comparing lists, they will be equal if contain the same data.
Examples
(= 3 3 (+ 2 1))
true
(= 3 3 1)
false
(= (1 2) (list 1 2))
true
(= (1 2) ("a" => 1 2))
true
==

==

Synopsis
Test if arguments are equal comparing list names.
Usage
(== value ... value)
Returns
result
Where
  • value is object[0..N]: a value to compare.
  • result is boolean: true if all arguments are equal, false otherwise.
Description
Returns true if all arguments are equal, false otherwise. When comparing lists, they will be equal if contain the same data and the same structure.
Examples
(== (1 2) ("a" => 1 2))
false
(== ("a" => 1 2) ("a" => 1 2))
true
===

===

Synopsis
Test if arguments are exactly equal.
Usage
(=== value ... value)
Returns
result
Where
  • value is object[0..N]: a value to compare.
  • result is boolean: true if all arguments are exactly equal, false otherwise.
Description
Returns true if all arguments are exactly equal (same subtype and value), false otherwise. When comparing lists, they will be equal if they are the same.
Examples
(=== 3 3 (+ 2 1))
false
(=== 3.5 (+ 2 1.5))
true
(=== (1 2) (list 1 2))
false
(do
  (set lst (1 2 3))
  (=== lst lst)
)
true
>

>

Synopsis
Test if one value is greater than another.
Usage
(> value ... value)
Returns
result
Where
  • value is object[0..N]: a value to compare.
  • result is boolean: true if for each two consecutive arguments the first one is greater than the second one. False otherwise.
Description
Returns true if for each two consecutive arguments the first one is greater than the second one. Returns false otherwise.
Examples
(> 3 2 1)
true
>=

>=

Synopsis
Test if one value is greater than or equal to another.
Usage
(>= value ... value)
Returns
result
Where
  • value is object[0..N]: a value to compare.
  • result is boolean: true if for each two consecutive arguments the first one is greater than or equal to the second one. False otherwise.
Description
Returns true if for each two consecutive arguments the first one is greater than or equal to the second one. Returns false otherwise.
Examples
(>= 3 2 2 1)
true
abs

abs

Synopsis
Absolute value of a number.
Usage
(abs value)
Returns
result
Where
  • value is number: the number whose absolute value is to be determined.
  • result is number: the absolute value of the specified number.
Description
Returns the absolute value of the given number.
Examples
(abs -7.9)
7.9
acos

acos

Synopsis
Arc cosine of a value.
Usage
(acos value)
Returns
angle_rad
Where
  • value is number: the argument whose arc cosine is to be determined.
  • angle_rad is number: an angle expressed in radians.
Description
Returns the trigonometric arc cosine of a value.
Examples
(acos 0.5)
1.0471975511965979
Related functions
and

and

Synopsis
Logical AND operation.
Usage
(and value ... value)
Returns
result
Where
  • value is boolean[0..N]: a boolean value to apply the and operation.
  • result is boolean: true if all its arguments are true, false otherwise.
Description
Returns the result of applying a logical AND operation on its boolean arguments.
Examples
(and true false true)
false
(and 1 5)
true
append

append

Synopsis
Appends the elements in a list to another list.
Usage
(append list1 list2)
Returns
result
Where
  • list1 is list: the target list.
  • list2 is list: the list whose elements will be appended to the first list.
  • result is list: the first list containing its own elements and the elements in the second list.
Description
Appends the elements in the second list to the first list. Names in the second list are also added to the first list.
If a name in the second list was already present in the first list, the value associated with that name in the first list is replaced by the value from the second list.
Examples
(append (1 2 3) (4 5 6))
(1 2 3 4 5 6)
(append (1 "a" => 2) (3 "a" => 8 9))
(1 "a" => 8 3 9)
apply

apply

Synopsis
Creates a new list by evaluating an expression for each element in a list.
Usage
(apply lst elem_var expression)
Returns
result
Where
  • lst is list: the list to apply the expression.
  • elem_var is reference: iteration variable defined in local scope that represents each element in the list.
  • expression is object: the expression to apply to each element in the given list.
  • result is list: a new list that is the result of evaluating the specified expression for each element in the given list.
Description
Returns a new list that is the result of evaluating the specified expression for each element in the given list.
Examples
(apply (1 2 3) x (* 2 x))
(2 4 6)
(apply ("a" => 2 3 "b" => 7) x (* x x))
("a" => 4 9 "b" => 49)
asin

asin

Synopsis
Arc sine of a value.
Usage
(asin value)
Returns
angle_rad
Where
  • value is number: the argument whose arc sine is to be determined.
  • angle_rad is number: an angle expressed in radians.
Description
Returns the trigonometric arc sine of a value.
Examples
(asin 1)
1.5707963267948966
Related functions
assert

assert

Synopsis
Checks if an expression is true
Usage
(assert expression message)
Returns
result
Where
  • expression is object: the expression to evaluate.
  • message is string[0..1]: the message to throw when expression is false.
  • result is object: the result of evaluating the expression.
Description
This function evaluates expression an throws an exception if the result converted to boolean is false. Otherwise returns the result of the evaluation.
Exceptions
  • "AssertFailed": when the assert expression evaluates to false.
Examples
(assert (= (+ 3 4) 7))
true
(assert (= (+ 3 4) 8))
("AssertFailed" "(= (+ 3 4) 8)")
atan

atan

Synopsis
Arc tangent of a value.
Usage
(atan value)
Returns
angle_rad
Where
  • value is number: the argument whose arc tangent is to be determined.
  • angle_rad is number: an angle expressed in radians.
Description
Returns the trigonometric arc tangent of a value.
Examples
(atan 0.5)
0.4636476090008061
Related functions
bit-and

bit-and

Synopsis
Bitwise AND operation.
Usage
(bit-and int_value ... int_value)
Returns
result
Where
  • int_value is number[0..N]: an integer value.
  • result is number: an integer that is the result of a bitwise OR operation on its arguments.
Description
Returns the result of applying a bitwise AND operation on all its arguments.
Examples
(bit-and 255 244)
244
Related functions
bit-not

bit-not

Synopsis
Bitwise NOT operation.
Usage
(bit-not int_value)
Returns
result
Where
  • int_value is number: an integer value.
  • result is number: an integer that is the result of a bitwise NOT operation on the specified argument.
Description
Returns the result of applying a bitwise NOT operation on the specified argument.
Examples
(bit-not 255)
-256
(bit-and (bit-not 240) 255)
15
Related functions
bit-or

bit-or

Synopsis
Bitwise OR operation.
Usage
(bit-or int_value ... int_value)
Returns
result
Where
  • int_value is number[0..N]: an integer value.
  • result is number
Description
Returns the result of applying a bitwise OR operation on all its arguments.
Examples
(bit-or 240 15)
255
Related functions
bit-shift

bit-shift

Synopsis
Shift bits.
Usage
(bit-shift int_value shift)
Returns
result
Where
  • int_value is number: an integer value.
  • shift is number: the number of bits to shift. The signum of this parameter determines the direction of the shifting.
  • result is number: the result of shifting int_value the specified number of bits.
Description
Shifts int_value the absolute number of shift bits to the left if shift is negative or the right if shift is positive. No shift is done when shift is zero.
Examples
(bit-shift 1 -4)
16
(bit-shift 16 4)
1
(bit-shift 16 0)
16
Related functions
bit-xor

bit-xor

Synopsis
Bitwise XOR operation.
Usage
(bit-xor int_value ... int_value)
Returns
result
Where
  • int_value is number[0..N]: an integer value.
  • result is number: an integer that is the result of a bitwise XOR operation on its arguments.
Description
Returns the result of applying a bitwise XOR operation on all its arguments.
Examples
(bit-xor 240 0)
240
Related functions
boolean

boolean

Synopsis
Converts an expression to boolean
Usage
(boolean expression)
Returns
result
Where
  • expression is object: the expression to convert to boolean.
  • result is boolean: the result of converting the expression to boolean.
Description
Converfts the given expression to boolean.
Examples
(boolean "false")
false
(boolean 0)
false
(boolean (1 2))
true
(boolean ())
false
Related functions
call

call

Synopsis
Invokes a function with parameters.
Usage
(call func parameter ... parameter)
Returns
result
Where
  • func is function: the function to call. It can be a native function, a variable referencing a function or a function definition.
  • parameter is object[0..N]: a parameter value.
  • result is object: the result returned by function func.
Description
Invokes the function with the specified parameters.
Examples
(call + 4 5)
9
(call (function (x) (* 2 x)) 5)
10
Related functions
ceil

ceil

Synopsis
Gets the smallest integer number that is greater than or equal to a value.
Usage
(ceil value)
Returns
result
Where
  • value is number: a double value.
  • result is number: the smallest integer number that is greater than or equal to the specified value.
Description
Returns the smallest (closest to negative infinity) integer number that is greater than or equal to the specified value.
Examples
(ceil 7.2)
8
Related functions
clone

clone

Synopsis
Clones a list.
Usage
(clone lst recursive)
Returns
result
Where
  • lst is list: the list to be cloned.
  • recursive is boolean[0..1]: a boolean indicating if cloning is performed recursivelly.
  • result is list: a new list that is a copy of the original.
Description
Creates a copy of the specified list. When recursive is true all elements in the list are cloned recursively. When not, only the given list is cloned but not the elements it contains.
Examples
(clone (1 2 (2 4)))
(1 2 (2 4))
(do
  (set fn (function (x) (* 2 x)))
  (=== fn (clone fn true))
)
false
concat

concat

Synopsis
Concatenates strings.
Usage
(concat str ... str)
Returns
result
Where
  • str is string[0..N]: a string to concatenate.
  • result is string: a new string that is the result of concatenating its arguments.
Description
Returns a new string that is the result of concatenating its arguments.
Examples
(do
  (set name "HAL")
  (concat "My name is " name)
)
"My name is HAL"
cond

cond

Synopsis
Multiple conditional function.
Usage
(cond
  when_clause
  ...
  when_clause
)
Returns
null
Where
  • when_clause is object[0..N]: a when clause (when condition action ... action).
Description
Executes the actions of the first when clause which condition evaluates to true.
Examples
(do
  (set a 1)
  (set b 0)
  (cond
    (when (= a 1)
      (-- b)
    )
    (when (= a 2)
      (++ b)
    )
    (when true
      (set b 0)
    )
  )
  b
)
-1
Related functions
cos

cos

Synopsis
Cosinus of an angle.
Usage
(cos angle_rad)
Returns
value
Where
  • angle_rad is number: an angle expressed in radians.
  • value is number: the cosine of angle_rad.
Description
Returns de trigonometric cosine of an angle expressed in radians.
Examples
(cos 3.1)
0.9991351502732795
Related functions
date

date

Synopsis
Date management.
Usage
(date operation date_millis field value)
Returns
result
Where
  • operation is string[0..1]: the operation to perform: "now" to get the current time, "add" to add a value to a date field of date_millis and "set" to set a value for a date field of date_millis. The operation, when omitted, is "now".
  • date_millis is number[0..1]: a date/time expressed as the number of milliseconds elapsed since january 1st 1970 00:00h.
  • field is string[0..1]: the field date to add or set. It can be one of the following: "year", "day_of_month", "day_of_week", "day_of_year", "hour_of_day", "hour", "month", "week_of_month", "week_of_year", "minute", "second" or "millisecond".
  • value is number[0..1]: the value to add or set to a date field.
  • result is number: a date/time expressed in milliseconds that is the result of performing the specified operation ("now", "add" or "set") on the given arguments.
Description
This function can get the current date in milliseconds or change a date field on the given date.
Examples
(date)
1509266462425
(date "now")
1509266462625
(date "add" (date) "day" -7)
1508657988101
(date "set" (date) "day_of_month" 3)
1507016618627
Related functions
delete

delete

Synopsis
Deletes a variable from the current context.
Usage
(delete variable)
Returns
result
Where
  • variable is reference: a reference to the variable to delete.
  • result is boolean: true if variable exists in the current context, false otherwise.
Description
Deletes the specified variable from the local scope if found, or the global scope, if not. This argument is not evaluated if it is already a reference.
Examples
(delete counter)
Related functions
div

div

Synopsis
Division of 2 integer numbers.
Usage
(div dividend divisor)
Returns
result
Where
  • dividend is number: the dividend of the division converted to integer.
  • divisor is number: the divisor of the division converted to integer.
  • result is number: an integer that is the result of dividing dividend by divisor.
Description
Returns the division of the specified integer numbers.
Examples
(/ 3 2)
1
Related functions
do

do

Synopsis
Executes a sequence of actions.
Usage
(do
  action
  ...
  action
)
Returns
result
Where
  • action is object[0..N]: expression to be evaluated.
  • result is object: the result of evaluating the last argument. If no arguments are provided, null is returned.
Description
All arguments are evaluated in order of appeareance and returns the result of the last evaluation.
Examples
(do
  (set counter 0)
  (if (> a 2) (++ counter))
)
downcase

downcase

Synopsis
Converts string to lowercase.
Usage
(downcase str)
Returns
result
Where
  • str is string: the string to downcase.
  • result is string: the given string converted to lowercase.
Description
Returns the specified string converted to lowercase.
Examples
(downcase "ABCD123f")
"abcd123f"
Related functions
empty

empty

Synopsis
Test if a list is empty.
Usage
(empty lst)
Returns
result
Where
  • lst is list: the list to test if it is empty.
  • result is boolean: true if list is empty or false if contains an element.
Description
Returns true if the given list is empty, false otherwise.
Examples
(empty (1 2 4))
false
(empty ())
true
eval

eval

Synopsis
Evaluates an expression.
Usage
(eval expression local_scope)
Returns
result
Where
  • expression is object: any expression.
  • local_scope is list[0..1]: a list representing the local scope in which the expression will be evaluated.
  • result is object: the result of evaluating the expression.
Description
This function evaluates the given expression in the current local scope. The result of that evaluation is evaluated again in the specified local_scope. If local_scope is omitted or is null, the current local scope is used.
Examples
(eval (quote (+ 4 5)))
9
(do
  (set sum_code (list + 2 4))
  (eval sum_code)
)
6
(eval (quote (+ x 2)) ("x" => 3))
5
Related functions
executors

executors

Synopsis
List all running executors.
Usage
(executors)
Returns
(executor_code ... executor_code)
Where
  • executor_code is object[0..N]: the code that is running the executor.
Description
This function returns a list that contains for each executor, the code that it is running. All code elements are named with the executor identifier.
Examples
(executors)
("23" => (eval loop) "25" => (executors))
Related functions
exists

exists

Synopsis
Checks the existence of a variable in the current context.
Usage
(exists variable)
Returns
result
Where
  • variable is reference: a reference to the variable to check its existence.
  • result is boolean: true if variable exists in the current context, false otherwise.
Description
Checks if the given variable exists in the current context. Returns true if variable is found in local or global scope and returns false otherwise. This argument is not evaluated if it is already a reference.
Examples
(exists counter)
false
Related functions
find

find

Synopsis
Find the elements in a list that meet a condition.
Usage
(find lst elem_var condition)
Returns
result
Where
  • lst is list: the list in which to look for the elements.
  • elem_var is reference: iteration variable defined in local scope that represents each element in the list.
  • condition is boolean: the condition (a boolean expression) that elements must meet.
  • result is list: new list that contains all the elements in the given list that meet the specified condition. If no element meets the condition, the returned list will be empty.
Description
Returns a new list that contains all the elements in the given list that meet the specified condition.
Examples
(find (2 4 7) x (= (mod x 2) 0))
(2 4)
(find ("a" => 2 "b" => 3 4) x (= (mod x 2) 0))
("a" => 2 4)
Related functions
first

first

Synopsis
Get the first element from a list.
Usage
(first lst)
Returns
result
Where
  • lst is list: the list from which to obtain the first element.
  • result is object: the first element in the list or null is the list is empty.
Description
Returns the first element from the given list or null if the list is empty.
Examples
(first (1 2 3))
1
(first ())
null
Related functions
floor

floor

Synopsis
Gets the largest integer number that is less than or equal to a value.
Usage
(floor value)
Returns
result
Where
  • value is number: a double value.
  • result is number: the largest integer number that is less than or equal to the specified value.
Description
Returns the largest (closest to positive infinity) integer number that is less than or equal to the specified value.
Examples
(floor 7.2)
7
Related functions
for

for

Synopsis
For loop.
Usage
(for init_code condition iter_code
  action
  ...
  action
)
Returns
result
Where
  • init_code is object: initialization code executed once before enter the loop. Tipically this code initializes an iteration variable.
  • condition is boolean: loop condition that usually involves an iteration variable.
  • iter_code is object: code that is executed at the end of each iteration. Usually this code increments an iteration variable.
  • action is object[0..N]: code to execute for each iteration.
  • result is object: the result of evaluating the last action or null is no action is specified.
Description
Executes a sequence of actions while a condition is true. This condition usually involves an iteration variable.
Examples
(for (set i 0) (< i 5) (++ i)
  (push lst i)
)
(0 1 2 3 4)
Related functions
for-each

for-each

Synopsis
Executes an action for each element in a list.
Usage
(for-each lst elem_var action ... action)
Returns
result
Where
  • lst is list: the list to iterate.
  • elem_var is reference: iteration variable defined in local scope that represents each element in the list.
  • action is object[0..N]: an action to execute for each element in the list.
  • result is object: the result of evaluating the last action for the last element in the list.
Description
Executes an action for each element in the given list.
Examples
(for-each (1 2 3) x (push lst (* 2 x)))
format-date

format-date

Synopsis
Formats date to string.
Usage
(format-date date_millis date_pattern language)
Returns
date_string
Where
  • date_millis is number: a date/time expressed as the number of milliseconds elapsed since january 1st 1970 00:00h.
  • date_pattern is string[0..1]: a date pattern as specified in https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html. When omitted, the default system date pattern is used.
  • language is string[0..1]: the ISO 639 alpha-2 or alpha-3 language code. By default, the system language is assumed.
  • date_string is string: a date/time represented as string.
Description
Formats a date/time expressed in milliseconds to string using the specified date pattern.
Examples
(format-date)
"29-oct-2017 9:46:29"
(format-date (date) "yyyy/MM/dd")
"2017/10/29"
Related functions
function

function

Synopsis
Creates a user function.
Usage
(function (parameter ... parameter)
  action
  ...
  action
)
Returns
result
Where
  • parameter is reference[0..N]: the variable name that will hold the parameter value.
  • action is object[0..N]: an action to execute. The value returned by the function is the result of evaluating the last expression of the function.
  • result is object: a list that represents the function definition.
Description
Creates a user function with the specified parameters and body.
Examples
(function (x y) (+ x y))
Related functions
functions

functions

Synopsis
List avaliable functions.
Usage
(functions pattern)
Returns
(func_ref ... func_ref)
Where
Description
Returns the list of function references that match a given pattern sorted by name.
Examples
(functions "si.*")
(sin size)
Related functions
get

get

Synopsis
Gets an element from a list.
Usage
(get lst spec)
Returns
result
Where
  • lst is list: the list from which to obtain an element.
  • spec is object: index, name or path list of the element.
  • result is list: the element from the list referenced by spec.
Description
Returns an element from the given list by index, by name or by path.
Examples
(get (1 2 3) 0)
1
(get (1 (2 3)) (1 0))
2
(get ("a" => 1 "b" => 2) "b")
2
Related functions
get-name

get-name

Synopsis
Gets the name of a position from a list.
Usage
(get-name lst index)
Returns
result
Where
  • lst is list: the list from which to obtain a name.
  • index is number: the index in the list to obtain the name.
  • result is list: the name at index position of the given list or null if this position has no name.
Description
Gets the name of the specified index in the given list.
Examples
(get-name ("a" => 2 "b" => 5) 1)
"b"
(get-name (3 "a" => 2 "b" => 5) 0)
null
Related functions
global-scope

global-scope

Synopsis
Returns the global scope list.
Usage
(global-scope)
Returns
result
Where
  • result is list: a list containing all elements of global scope.
Description
Returns a list that contains all name/value pairs of the global scope of the current context.
Examples
(global-scope)
("counter" => 8 "lst" => (1 2 3))
Related functions
has

has

Synopsis
Test if a list has a name or can be acceded by an index.
Usage
(has lst spec)
Returns
result
Where
  • lst is list: the list to determine if can be acceded by the given name or index.
  • spec is object: index, name or path list of the element.
  • result is list: true if list can be acceded by spec or false otherwise.
Description
When spec is a name, this function returns true if list has this name or false otherwise. When spec is a number, this function returns true only if spec is >= 0 and < list size.
Examples
(has (1 2 3) 0)
true
(has (1 2 3) 3)
false
(has (1 "x" => 2 3) "x")
true
(has (1 "x" => 2 3) "y")
false
help

help

Synopsis
Gets help for a function.
Usage
(help
  func
  "format" => format
  "language" => language
)
Returns
result
Where
  • func is reference: reference to native o user function. This argument is not evaluated if it is already a reference.
  • format is string: can be "string" or "list". If omitted, format is "string".
  • language is string: the ISO 639 alpha-2 or alpha-3 language code representing the language of texts returned by this function. By default, the system language is assumed.
  • result is object: a help list when format is "list" or a string when format is "string".
Description
Gets help for a function in the specified format and language.
Examples
(help sin)
http

http

Synopsis
HTTP request.
Usage
(http
  method
  url
  "body" => data
  "properties" => properties
  "connect-timeout" => connect_timeout
  "read-timeout" => read_timeout
  "input-format" => input_format
  "output-format" => output_format
  "download-file" => download_file
  "upload-file" => upload_file
)
Returns
(
  "status" => status
  "message" => message
  "headers" => headers
  "body" => body
)
Where
  • method is string: HTTP method ("GET", "POST", "PUT", "DELETE", etc.).
  • url is string: URL to request.
  • data is object[0..1]: data to send in POST and PUT methods.
  • properties is list[0..1]: HTTP header properties to send in request (list of name/value pairs).
  • connect_timeout is number[0..1]: connect timeout in milliseconds.
  • read_timeout is number[0..1]: read timeout in milliseconds.
  • input_format is string[0..1]: the format to convert data parameter to string ("bpl", "json", "xml" or "string"). By default, "string" format is assumed.
  • output_format is string[0..1]: format to convert response body string to data ("bpl", "json", "xml" or "string"). By default, "string" format is assumed.
  • download_file is string[0..1]: the path of the file to download the response.
  • upload_file is string[0..1]: the path of the file to upload.
  • status is number: the HTTP result code
  • message is string: the HTTP result message
  • headers is list: the HTTP response headers
  • body is object: the HTTP response body
Description
Performs an HTTP request to the resource identified by url.
Exceptions
  • "MalformedURLException": when the url format is invalid.
  • "UnknownHostException": when host name can not be resolved.
  • "ConnectException": when connection is refused.
  • "TimeoutException": when the host does not response for the given timeouts.
  • "IOException": when an error occurs while reading or writing data.
Examples
(http "GET" "http://brain4it.org")
(http
  "PUT"
  "http://smart.sfl.cat/api"
  "body" => "{data: 67}"
)
if

if

Synopsis
Conditional function.
Usage
(if condition action_when_true action_when_false)
Returns
result
Where
  • condition is boolean: the condition to evaluate.
  • action_when_true is object: expression to evaluate when codition is true.
  • action_when_false is object[0..1]: expression to evaluate when condition is false.
  • result is object: the last evaluated expression or null if no action is executed.
Description
Executes action_when_true when condition is true or action_when_false otherwise.
Examples
(if (= 1 1) 23)
23
(if (> 1 2) "GREATER" "LESS")
"LESS"
Related functions
insert

insert

Synopsis
Inserts an element into a list.
Usage
(insert lst index element)
Returns
result
Where
  • lst is list: the list in which to insert the element.
  • index is number[0..1]: the index where the element is to be inserted.
  • element is object: the element to be inserted.
  • result is number: the list passed as argument containing the new inserted element.
Description
Inserts the specified element into the given list at the specified index.
Examples
(insert (1 2 4) 2 3)
(1 2 3 4)
Related functions
kill

kill

Synopsis
Kills a executor thread.
Usage
(kill executor_id)
Returns
result
Where
  • executor_id is number: identifier of the executor to kill. If omitted, all executors of the current context will be killed.
  • result is boolean: true if one or more executors were killed, false otherwise.
Description
Stops the executor thread identified by executor_id. Returns true if at least one executor was killed.
Examples
(kill 23)
true
(kill)
true
Related functions
last

last

Synopsis
Gets the last element from a list.
Usage
(last lst)
Returns
result
Where
  • lst is list: the list from which to obtain the last element.
  • result is object: the last element in the list or null if the list is empty.
Description
Returns the last element from the given list or null if the list is empty.
Examples
(last (1 2 3))
3
(last ())
null
Related functions
length

length

Synopsis
Gets the length of a string.
Usage
(length str)
Returns
result
Where
  • str is string: the string to get the length.
  • result is number: the number of characters of the given string.
Description
Returns the number of characters of the given string.
Examples
(length "Brain4it")
8
list

list

Synopsis
Creates a new list.
Usage
(list value ... value)
Returns
result
Where
  • value is object[0..N]: a value to add to the list. It may have a name.
  • result is object: a new list that contains the arguments of this function call.
Description
Creates a new list and adds the arguments to it. If arguments have names, they are also added to the list.
Examples
(list "a" => (+ 1 2) 6)
("a" => 3 6)
(list + 3 (* 2 2))
(+ 3 4)
local

local

Synopsis
Declares variables in local scope.
Usage
(local variable ... variable)
Returns
null
Where
  • variable is reference[0..N]: a reference to the variable to declare. This argument is not evaluated if it is already a reference.
Description
Declares the specified variables in local scope.
Examples
(local counter sensor_value)
Related functions
local-scope

local-scope

Synopsis
Returns the local scope list.
Usage
(local-scope depth)
Returns
result
Where
  • depth is number[0..1]: is an index in the stack of local scopes. When depth is 0 this function returns the current local scope. If depth is 1 it returns the parent local scope. When depth references an invalid local scope this function returns null. By default, depth is 0.
  • result is list: a list that contains all the variables of the specified local scope.
Description
Returns a list that contains all the variables (name/value pairs) of the local scope of the current context.
Examples
(do
  (local a b)
  (set a 8)
  (set b 6)
  (local-scope)
)
("a" => 8 "b" => 6)
(do
  (set fn
    (function (x)
      (put (local-scope 1) "y" (+ x 1))
    )
  )
  (local x)
  (set x 5)
  (fn (* 2 x))
  (local-scope)
)
("x" => 5 "y" => 11)
Related functions
locate

locate

Synopsis
Gets the location of the first element in a list that meets a condition.
Usage
(locate lst elem_var condition from_index)
Returns
result
Where
  • lst is list: the list to look for the element.
  • elem_var is reference: iteration variable defined in local scope that represents each element in the list.
  • condition is object: the condition to meet.
  • from_index is number[0..1]: the index from which to start the search.
  • result is number: the index of the first element in the list that meets the condition.
Description
Returns the index of the first element in the given list starting at from_index that meets the specified condition or -1 if no element meets that condition.
Examples
(locate (2 5 7) x (= x 5))
1
(locate (2 5 5) x (= x 5) 2)
2
Related functions
locate-string

locate-string

Synopsis
Gets the location of the first occurrence of a substring inside a string.
Usage
(locate-string str substring from_index)
Returns
result
Where
  • str is string: the string to find the substring in.
  • substring is string: the substring to locate.
  • from_index is number[0..1]: the starting index to find the substring.
  • result is number: the location of the first occurrence of substring starting at from_index.
Description
Returns the location within the given string of the first occurrence of the specified substring, starting at the specified from_index.
Examples
(locate-string "My car is red" "is")
7
(locate-string "My car is red" "r")
5
(locate-string "My car is red" "r" 7)
10
Related functions
log10

log10

Synopsis
Base 10 logarithm of a value.
Usage
(log10 value)
Returns
result
Where
  • value is number: the value to get the base 10 logarithm.
  • result is number: the base 10 logarithm of value.
Description
Returns the base 10 logarithm of a value.
Examples
(log10 5)
0.6989700043360189
Related functions
logn

logn

Synopsis
Natural logarithm of a value.
Usage
(logn value)
Returns
result
Where
  • value is number: the value to get the natural logarithm.
  • result is number: the natural logarithm of value.
Description
Returns the natural logarithm (base e) of a value.
Examples
(logn 5)
1.6094379124341003
Related functions
match

match

Synopsis
Matches a list with a pattern.
Usage
(match lst list_pattern expression)
Returns
match_found
Where
  • lst is list: the list to match.
  • list_pattern is list: the list pattern. It may contain two kind of substitution variables: single variables ending with a question mark (ex: x?, y?) or list variables ending with 3 dots (ex: a..., b...). Single variables substitute a single element, while list variables may substitute from 0 to N consecutive elements.
  • expression is object[0..1]: the expression to evaluate for each match found. It may perform some test on the substitution variables or may do changes in the first list. The expression must return false to continue the matching process or true to stop it. When omitted, expression is true.
  • match_found is boolean: true if a match was found of false if not.
Description
This function matches the given list and all its sublists with the specified list pattern. If a match is found, the substitution variables in the list pattern are set in local context and the given expression is evaluated. Some special variables are also set for each match: match_parent$, match_position$ and match_map$. match_parent$ is the parent list of the match, match_position$ is the position in match_parent$ list where the match was found, and match_map$ is a list that contains all the substitution variables as name/value pairs. If the evaluation of the expression returns false, the matching process continues. It the evaluation returns true, the matching process stops and the function returns true. When no match is found or the specified expression never returns true, the function returns false.
Examples
(match
  (quote (* a (+ a 3) c))
  (quote (+ a? b?))
  (= (type-of b?) "number")
)
true
Related functions
match-string

match-string

Synopsis
Matches a string with a regular expression.
Usage
(match-string str reg_exp)
Returns
matches
Where
Description
Tells whether or not the given string matches the specified regular expression.
Examples
(match-string "Hello" ".*e.*")
true
Related functions
merge

merge

Synopsis
Replaces variables in a list.
Usage
(merge lst variables)
Returns
result
Where
  • lst is list: the list that may contain variables (references). It can also be a single variable or a literal.
  • variables is list: a list with name/value pairs.
  • result is object: a new list that is a copy of the original with the variables replaced.
Description
For each reference in the first list that is found as a name is the second list, it is replaced by the value associated to that name in the second list.
Examples
(merge
  (quote (+ 2 3 x (* x y)))
  ("x" => 4 "y" => 5)
)
(+ 2 3 4 (* 4 5))
Related functions
mod

mod

Synopsis
Remainder of a division.
Usage
(mod dividend divisor)
Returns
result
Where
  • dividend is number: the dividend of the division.
  • divisor is number: the divisor of the division.
  • result is number: the remainder of the division of dividend by divisor.
Description
Returns the remainder of the division of the specified numbers.
Examples
(mod 20 3)
2
name-index

name-index

Synopsis
Gets the index associated to a name in a list.
Usage
(name-index lst name)
Returns
index
Where
  • lst is list: the list from which to obtain the index of the name.
  • name is string: the name whose index is to be determined.
  • index is number: the index of the specified name or -1 if the given list does not have this name.
Description
Returns the index of the element in the given list that has the specified name.
Examples
(name-index ("a" => 4 "b" => 6) "b")
1
Related functions
names

names

Synopsis
Gets the names from a list.
Usage
(names lst)
Returns
result
Where
  • lst is list: the list from which to obtain the names.
  • result is list: a new list that contains all the names of the given list in order of appearance.
Description
Returns a new list that contains all the names of the given list in order of appearance. If the list has no names, an empty list is returned.
Examples
(names ("a" => 5 8 9 "b" => 3))
("a" "b")
Related functions
not

not

Synopsis
Logical NOT operation.
Usage
(not value)
Returns
result
Where
  • value is boolean: a boolean value to apply the not operation.
  • result is boolean: true if argument is false, false otherwise.
Description
Returns the result of applying a logical NOT operation on its boolean argument.
Examples
(not true)
false
notify

notify

Synopsis
Notifies executors waiting for a monitor.
Usage
(notify monitor)
Returns
null
Where
  • monitor is object: the object monitor the executors are waiting for.
Description
Notifies all executors that are waiting for this monitor.
Examples
(notify lock)
Related functions
number

number

Synopsis
Converts a expression to number.
Usage
(number
  expression
  "radix" => radix
  "pattern" => pattern
  "locale" => locale
  "type" => type
)
Returns
result
Where
  • expression is object: the expression to convert to number.
  • radix is number[0..1]: a positive integer representing the radix of conversion.
  • pattern is string[0..1]: a Java DecimalFormat (https://docs.oracle.com/javase/7/docs/api/java/text/DecimalFormat.html) to parse the expression as number.
  • locale is string[0..1]: the locale of pattern.
  • type is string[0..1]: can be "integer", "long" or "double".
Description
Converts the given expression to number of type precision using the specified radix.
Exceptions
  • "NumberFormatException": when the given expression can not be converted to number.
Examples
(number "45")
45
(number "45.6" "pattern" => "0.0" "locale" => "en")
45.6
(number "1110" "radix" => 2)
14
(number 7.4 "type" => "integer")
7
Related functions
or

or

Synopsis
Logical OR operation.
Usage
(or value ... value)
Returns
result
Where
  • value is boolean[0..N]: a boolean value to apply the or operation.
  • result is boolean: true if any of its arguments is true, false otherwise.
Description
Returns the result of applying a logical OR operation on its boolean arguments.
Examples
(or true false (= 1 2))
true
parse

parse

Synopsis
Converts a string into a BPL object.
Usage
(parse str format)
Returns
result
Where
  • str is string: the string to be converted to list.
  • format is string[0..1]: the format of the given string. Can be "bpl", "json" or "xml". Default is "bpl".
  • result is object: a BPL object representing the data in the given string.
Description
Converts the given string represented in the specified format (string, bpl, json or xml) to a BPL object.
Exceptions
  • "ParseException": when the given string can not be parsed.
Examples
(parse "(1 2 3)")
(1 2 3)
(parse "[2, 4, 6]" "json")
(2 4 6)
Related functions
parse-date

parse-date

Synopsis
Converts string to date.
Usage
(parse-date date_string date_pattern language)
Returns
date_millis
Where
  • date_string is string: a date/time represented as string.
  • date_pattern is string[0..1]: a date pattern as specified in https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html. When omitted, the default system date pattern is used.
  • language is string[0..1]: the ISO 639 alpha-2 or alpha-3 language code. By default, the system language is assumed.
  • date_millis is number: a date/time expressed as the number of milliseconds elapsed since january 1st 1970 00:00h.
Description
Converts a string representing a date/time to milliseconds using the specified date pattern.
Examples
(parse-date "25/02/1973" "dd/MM/yyyy")
99442800000
Related functions
pop

pop

Synopsis
Extracts and returns the last element from a list.
Usage
(pop lst)
Returns
result
Where
  • lst is list: the list from which to extract the last element.
  • result is object: the last element from the list or null if the list is empty.
Description
Extracts and returns the last element from the given list or null if the list is empty.
Examples
(pop (1 2 3))
3
Related functions
pow

pow

Synopsis
Raises a value.
Usage
(pow value exponent)
Returns
result
Where
  • value is number: the value to raise.
  • exponent is number: the exponent.
  • result is number: value raised to the power of exponent.
Description
Returns the given value raised to the power of the specified exponent.
Examples
(pow 2 8)
256
Related functions
push

push

Synopsis
Adds an element to a list.
Usage
(push lst element)
Returns
result
Where
  • lst is list: the list in which to add the element.
  • element is object: the element to add to the list.
  • result is list: the list passed as argument containing the specified element at the last position.
Description
Adds the specified element to the given list.
Examples
(push (1 2) 3)
(1 2 3)
Related functions
put

put

Synopsis
Puts an element in a position of a list.
Usage
(put lst spec element)
Returns
result
Where
  • lst is list: the list in which to put the element.
  • spec is object: index, name or path list of the element.
  • element is object: the element to be putted.
  • result is object: the previous element at the position that has been modified.
Description
Replaces the element in the given list at the specified index, name or path with the given element.
Examples
(put (1 2 3) 0 9)
1
(put (1 (2 3)) (1 0) 9)
2
(do
  (set lst (1 2))
  (put lst 4 3)
  lst
)
(1 2 null null 3)
(do
  (set lst ("a" => 1 "b" => 2))
  (put lst "b" 0)
  lst
)
("a" => 1 "b" => 0)
put-name

put-name

Synopsis
Sets the name to a position in a list.
Usage
(put-name lst index name)
Returns
result
Where
  • lst is list: the list in which to set the name.
  • index is number: the position where to put the name.
  • name is string: the name to put.
  • result is list: the list passed as argument containing the specified name at the given index.
Description
Sets the name to the specified index in the given list.
Examples
(put-name (1 2 3) 1 "a")
(1 "a" => 2 3)
(put-name (1 "a" => 2 3) 1 null)
(1 2 3)
(put-name (1 "a" => 2 3) 2 "a")
(1 2 "a" => 3)
Related functions
quote

quote

Synopsis
Quotes an expression.
Usage
(quote expression)
Returns
result
Where
  • expression is object: the expression to quote.
  • result is object: the expression passed as argument.
Description
Returns the given expression as is, without evaluating it.
Examples
(quote (+ 3 a))
(+ 3 a)
Related functions
random

random

Synopsis
Random number generation.
Usage
(random max_value)
Returns
result
Where
  • max_value is number[0..1]: the max_value (excluded) that can return this function. If not specified, max_value is 1.
  • result is number: a value between 0 and max_value (excluded).
Description
Returns a random number between 0 and max_value (excluded).
Examples
(random 10)
8.836184088394907
reference

reference

Synopsis
Creates a reference from a string or a path list.
Usage
(reference expression)
Returns
result
Where
  • expression is object: the expression to convert to reference. It can be a string containing the reference value, a path list or a reference. Path lists can only contain strings and non negative integers and the first element must be a string.
  • result is reference: the reference represented by expression.
Description
Creates a soft or hard reference from the specified string or path list.
Exceptions
  • "InvalidReference": when the given string or path list can not be converted to reference.
Examples
(reference "persons")
persons
(reference (quote alfa))
alfa
(reference "persons/5/name")
persons/5/name
(reference ("persons" 5 "name"))
persons/5/name
(reference ("Hello friend" "John Connor"))
/"Hello friend"/"John Connor"
Related functions
reference-list

reference-list

Synopsis
Gets the path list of a reference.
Usage
(reference-list ref)
Returns
result
Where
  • ref is reference: the reference to obtain its path list.
  • result is list: a list representing the path list of ref.
Description
Returns a list that containts the path elements of the given reference.
Exceptions
  • "InvalidReference": when the given argument is not a reference.
Examples
(reference-list alfa)
("alfa")
(reference-list persons/5/name)
("persons" 5 "name")
(reference-list /"Hello world"/2/msg)
("Hello world" 2 "msg")
Related functions
remove

remove

Synopsis
Removes elements from a list.
Usage
(remove lst spec)
Returns
result
Where
  • lst is list: the list from which to remove elements.
  • spec is object[0..1]: index, name or path list of the element.
  • result is list: the element that was removed from the list or null if all elements where removed.
Description
Removes the specified element from the given list (by index, name or path) or removes all elements if spec is not defined.
Examples
(remove (1 2 3) 1)
2
(do
  (set lst ("a" => 1 "b" => 2))
  (remove lst "a")
  lst
)
("b" => 2)
Related functions
replace-string

replace-string

Synopsis
Replaces all occurrences of a pattern in a string with an other string.
Usage
(replace-string str reg_exp replace)
Returns
result
Where
Description
Returns a new string where all occurrences of the given pattern, expressed as a regular expression, have been replaced with the specified replacement string.
Examples
(replace-string "Hello" "ll" "r")
"Hero"
reverse

reverse

Synopsis
Reverses the elements of a list.
Usage
(reverse lst)
Returns
result
Where
  • lst is list: the list to be reversed.
  • result is list: a copy of the given list that has the elements in reserve order.
Description
Returns a new list that contains all the elements of the given list in reverse order.
Examples
(reverse (1 2 3))
(3 2 1)
round

round

Synopsis
Gets the closest integer number to a value.
Usage
(round value)
Returns
result
Where
  • value is number: a double value.
  • result is number: the closest integer number to the specified value.
Description
Returns the closest integer number to the specified value, with ties rounding to positive infinitive.
Examples
(round 7.8)
8
(round 7.5)
8
(round 7.4)
7
Related functions
set

set

Synopsis
Sets the value of a variable.
Usage
(set variable expression)
Returns
result
Where
  • variable is reference: a reference to the variable to set. This argument is not evaluated if it is already a reference.
  • expression is object: the value to assign to the variable.
  • result is object: the result of evaluating the expression.
Description
Assigns the result of evaluating the given expression to the specified variable.
Examples
(set counter (+ 3 4))
7
Related functions
set-local

set-local

Synopsis
Sets the value of a local variable.
Usage
(set-local variable expression)
Returns
result
Where
  • variable is reference: a reference to the local variable to set. This argument is not evaluated if it is already a reference.
  • expression is object: the value to assign to the variable.
  • result is object: the result of evaluating the expression.
Description
Assigns the result of evaluating the given expression to the specified local variable.
Examples
(do
  (set y 23)
  (set fn (function (x) (set-local y (+ x 23))))
  (fn 7)
  y
)
23
Related functions
sin

sin

Synopsis
Sinus of an angle.
Usage
(sin angle_rad)
Returns
value
Where
  • angle_rad is number: an angle expressed in radians.
  • value is number: the sine of angle_rad.
Description
Returns the trigonometric sine of an angle expressed in radians.
Examples
(sin 0.5)
0.479425538604203
Related functions
size

size

Synopsis
Returns the size of a list.
Usage
(size lst)
Returns
result
Where
  • lst is list: the list whose size is to be determined.
  • result is number: the number of elements in the list.
Description
Returns the number of elements in the list.
Examples
(size (1 2 3))
3
sleep

sleep

Synopsis
Pauses execution.
Usage
(sleep milliseconds)
Returns
null
Where
  • milliseconds is number: the number of milliseconds to sleep.
Description
Pauses the execution for the specified milliseconds.
Examples
(sleep 1000)
sort

sort

Synopsis
Sorts a list.
Usage
(sort lst comparator)
Returns
result
Where
  • lst is list: the list to sort.
  • comparator is function[0..1]: a user defined function that compares 2 values. It takes 2 arguments (x y), and must return a negative integer if x < y, a positive integer if x > y, or zero if x = y. When no comparator is specified, a default ascending order comparator is used.
  • result is list: a copy of the given list that contains the elements sorted by the specified comparator.
Description
Returns a new list that is the result of sorting the elements of given list. By default, this function sorts elements in ascending order, but a comparator function can be specified to order in other ways.
Examples
(sort (7 4 6))
(4 6 7)
(sort
  ((7) (4) (2))
  (function (a b) (- (first a) (first b)))
)
((2) (4) (7))
spawn

spawn

Synopsis
Creates a new executor.
Usage
(spawn action)
Returns
executor_id
Where
  • action is object: the action to execute in the new executor thread.
  • executor_id is string: the identifier of the new executor.
Description
Creates a new executor for running the specficied action.
Examples
(spawn (eval loop))
34
Related functions
split

split

Synopsis
Splits a string around matches of a regular expression.
Usage
(split str reg_exp)
Returns
(part ... part)
Where
Description
Splits the given string around matches of the specified regular expression. If regular expression is omitted, " " is used by default.
Examples
(split "My name is HAL")
("My" "name" "is" "HAL")
(split "1,2,3" "\\,")
("1" "2" "3")
sqrt

sqrt

Synopsis
Square root of a value.
Usage
(sqrt value)
Returns
result
Where
  • value is number: a value whose square root is to be determined.
  • result is number: the square root of value.
Description
Returns the square root of a value.
Examples
(sqrt 2)
1.4142135623730951
Related functions
string

string

Synopsis
Converts an expression to string.
Usage
(string
  expression
  "pattern" => pattern
  "locale" => locale
  "radix" => radix
  "unsigned" => unsigned
  "escape" => escape
  "format" => format
)
Returns
result
Where
  • expression is object: the expression to convert to string.
  • pattern is string[0..1]: a Java DecimalFormat or "unicode" to convert number to unicode char.
  • locale is string[0..1]: the locale of pattern.
  • radix is number[0..1]: the radix of conversion when the value to convert is a number.
  • unsigned is boolean[0..1]: when true, number is considered unsigned, otherwise signed.
  • escape is boolean[0..1]: a boolean indicating if the returned string is escaped or not.This option only applies when the given expression is already a string.
  • format is string[0..1]: the format to represent the expression when it is a list. Accepted values are "bpl", "json" or "xml". Default value is "bpl".
  • result is string: a string representing the result of evaluating expression.
Description
Converts the given expression of any type to string.
Examples
(string (+ 4 5))
"9"
(string
  5.3429
  "pattern" => "0.00"
  "locale" => "es"
)
"5,34"
(string (1 2 3) "format" => "json")
"[1,2,3]"
(string 23 "radix" => 16)
17
(string "Hello" "escape" => true)
"\"Hello\""
(string 225 "pattern" => "unicode")
"á"
Related functions
sublist

sublist

Synopsis
Returns a sublist of a list.
Usage
(sublist lst from_index to_index)
Returns
result
Where
  • lst is list: the list from which to obtain a sublist.
  • from_index is number: the starting index of the sublist.
  • to_index is number[0..1]: the ending index of the sublist (excluded). When omitted, to_index is equal to the size of the list.
  • result is list: a new list that contains the elements from from_index to to_index (excluded) in the given list.
Description
Returns a new list that contains the elements from the given list between from_index and to_index position.
Examples
(sublist (1 2 3 4 5) 2)
(3 4 5)
(sublist (1 2 3 4 5) 2 4)
(3 4)
substring

substring

Synopsis
Gets the fragment of a string between two indices.
Usage
(substring str from_index to_index)
Returns
result
Where
  • str is string: the string to extract a fragment.
  • from_index is number
  • to_index is number[0..1]: the ending index of the fragment. When omitted, this argument is equal to the length of the string.
Description
Returns the fragment of the given string between the specified indices.
Examples
(substring "Federation" 2 4)
"de"
(substring "Federation" 2)
"deration"
subtype-of

subtype-of

Synopsis
Returns the subtype of an expression.
Usage
(subtype-of expression)
Returns
result
Where
  • expression is object: the expression to obtain the subtype of.
  • result is string: can be "null", "integer", "long", "double", "string", "boolean", "data-refefence", "function-reference", "data-list", "code-list" or "function-list"
Description
Returns the specific type of the result of evaluating expression.
Examples
(subtype-of 7.4)
"double"
(subtype-of sin)
"function-reference"
Related functions
sync

sync

Synopsis
Synchronizes a code block.
Usage
(sync monitor action ... action)
Returns
result
Where
  • monitor is object: the monitor object to obtain the lock.
  • action is object[0..N]: an action to be executed.
  • result is object: the result of evaluating the last action or null is no action is specified.
Description
Executes a sequence of actions obtaining first the lock of a monitor.
Examples
(sync lock (++ counter) (test_sensor))
Related functions
system

system

Synopsis
Runs an operating system command.
Usage
(system command)
Returns
(exit_code output ... output)
Where
  • command is string: the command to run with parameters.
  • exit_code is number: the exit code returned by command.
  • output is string[0..N]: line read from standard output of command.
Description
Runs the specified operating system command and waits for response. It reads the standard output of this command and returns a list that contains the lines read.
Examples
(system "ls -la")
(0 "doc.txt 533" "work.xls 1235")
tan

tan

Synopsis
Tangent of an angle.
Usage
(tan angle_rad)
Returns
value
Where
  • angle_rad is number: an angle expressed in radians.
  • value is number: the tangent of angle_rad.
Description
Returns the trigonometric tangent of an angle expresses in radians.
Examples
(tan 1)
1.5574077246549023
throw

throw

Synopsis
Throws an exception.
Usage
(throw exception message)
Returns
null
Where
  • exception is object: the exception object. It can be an exception list ("ExceptionType" ...) or a string that represents the exception type.
  • message is message[0..1]: the message of the exception, when exception argument is not a list.
Description
Throws the exception object passed as argument.
Examples
(throw "InvalidNumber")
(throw "SensorFailed" "light-sensor-23")
(throw (list "InvalidData" "message" => data))
Related functions
timer-cancel

timer-cancel

Synopsis
Cancels a scheduled task.
Usage
(timer-cancel task_id)
Returns
cancelled
Where
  • task_id is number[0..1]: the task identifier.
  • cancelled is boolean: true if at least one task was cancelled, false otherwise.
Description
Cancels the scheduled task identified by task_id if it was created in the current context. When task_id is not specified, all tasks associated with the current context will be cancelled.
If the task is running when calling this function, it will continue to completion, but it will never run again.
Examples
(timer-cancel 37)
true
(timer-cancel)
true
Related functions
timer-schedule

timer-schedule

Synopsis
Schedules a task for future execution.
Usage
(timer-schedule func delay period overlap)
Returns
task_id
Where
  • func is function: the user function to execute.
  • delay is number: the delay in milliseconds before calling the function.
  • period is number[0..1]: the period in milliseconds for repeated execution.
  • overlap is boolean[0..1]: when true call overlap is allowed. By default overlap is false.
  • task_id is number: the task identifier that will be used later to cancel the task execution.
Description
Schedules a task that will call the given user function for execution after delay milliseconds.
If a period greater than zero is specified, the function will be called repeatedly at intervals of period milliseconds.
Each function call will always run in a different executor, so it does no matter how long it takes to finish.
By default, new calls are discarded while a previous one is still running. To allow call overlap, set overlap parameter to true.
Examples
(timer-schedule process_later 5000)
27
(timer-schedule eval_rules 0 60000)
29
(timer-schedule
  (function () (++ a))
  1000
  5000
  true
)
30
Related functions
timer-tasks

timer-tasks

Synopsis
Shows the current scheduled tasks.
Usage
(timer-tasks)
Returns
(task ... task)
Where
  • task is function[0..N]: the function associated with the task, named with its task_id.
Description
Returns a list that contains the task_id and the function code of the active tasks that were created in the current context.
Examples
(timer-tasks)
(
  "12" => (function () (++ a))
  "18" => (function () (check_system))
)
Related functions
trim

trim

Synopsis
Removes starting and ending spaces from a string.
Usage
(trim str)
Returns
result
Where
  • str is string: the string to trim.
  • result is string: the given string without starting and ending spaces.
Description
Returns the specified string without starting or ending spaces.
Examples
(trim " A sentence to trim. ")
"A sentence to trim."
try

try

Synopsis
Executes code catching exceptions.
Usage
(try main_action catch_actions finally_action)
Returns
result
Where
  • main_action is object: the action to execute that can throw an exception.
  • catch_actions is (excep_var catch_action ... catch_action): the list containing the catch actions or null if no exception is going to be catched.
  • excep_var is reference: the variable that holds the exception thrown by action.
  • catch_action is object[1..N]: a named action where its name is the type of exception that it handles. When name is "*", the corresponding action will handle any type of exception.
  • finally_action is object: an action that is always executed, whatever an exception is thrown or not.
  • result is object: the result of evaluating the main_action or in case that main_action throws an exception, the result of evaluating the catch_action that handles that exception.
Description
Executes the specified action catching exceptions with catch_action elements. Exceptions of type InterruptedException can not be catched.
Examples
(try (do_work) (ex "*" => null))
(try (do_work) null (release_resources))
(try
  (http "GET" "http://brain4it.org")
  (ex
    "IOException" => (set error 1)
    "ConnectException" => (set error 2)
    "*" => (set error ex)
  )
  (release_resources)
)
Related functions
type-of

type-of

Synopsis
Returns the type of an expression.
Usage
(type-of expression)
Returns
result
Where
  • expression is object: the expression to obtain the type of.
  • result is string: can be "null", "number", "string", "boolean", "reference" or "list".
Description
Returns the main type of the result of evaluating expression.
Examples
(type-of "Brain4it")
"string"
(type-of 45)
"number"
(type-of (quote alfa))
"reference"
Related functions
upcase

upcase

Synopsis
Converts string to uppercase.
Usage
(upcase string)
Returns
result
Where
  • string is string
  • result is string: the given string converted to uppercase.
Description
Returns the specified string converted to uppercase.
Examples
(upcase "Abc123")
"ABC123"
wait

wait

Synopsis
Waits for monitor notification.
Usage
(wait monitor milliseconds)
Returns
null
Where
  • monitor is reference: the monitor object to listen notifications from.
  • milliseconds is number[0..1]: the number of milliseconds to wait for a notification. If omitted, there is no wait.
Description
Pauses execution for the specified milliseconds or until a notification for this monitor is received.
Examples
(sync lock
  (while data
    (process_data data)
    (wait lock)
  )
)
Related functions
watch

watch

Synopsis
Watches for changes.
Usage
(watch expression value)
Returns
result
Where
  • expression is reference: the expression to evaluate.
  • value is object[0..1]: the value to compare with the result of evaluating expression. If omitted, value is assigned the result of expression.
  • result is object: the result of expression.
Description
Pauses execution until the result of evaluating expression is different of the specified value. If after 30 seconds no change is produced, the current value of expression is returned.
Examples
(watch sensor_value 78)
79
when

when

Synopsis
Executes a code block when a condition is true.
Usage
(when condition
  action
  ...
  action
)
Returns
result
Where
  • condition is boolean: the condition to evaluate. When it evaluates to false, the actions are not executed.
  • action is object[0..N]: an action to execute.
  • result is boolean: the result of evaluating the condition.
Description
Executes the specified sequence of actions if the given condition is true.
Examples
(when (= element/type "Computer")
  (process_elem element)
  (save_elem element)
  (push processed element)
)
true
Related functions
while

while

Synopsis
Executes a code block while a condition is true.
Usage
(while condition
  action
  ...
  action
)
Returns
result
Where
  • condition is boolean: the condition to evaluate. When it evaluates to false, the loop ends.
  • action is object[0..N]: an action to execute in each iteration.
  • result is object: the result of evaluating the last action.
Description
Executes the specified sequence of actions while the given condition is true.
Examples
(while (< i data_size)
  (process_data i)
  (++ i)
)
Related functions
Top