The interpreter module implements an extensible lisp-based scripting runtime.
See Also
PContext for the main class to run a script.
| Function | assert |
Assert that the symbol is a list of symbols, and that the list length is within the given arguments: either an exact length, or a minimum lenght and a maximum length. |
| Function | check |
Check for script timeout. |
| Function | evaluate |
Replace all inline expressions in a string. |
| Function | execute |
Recursively execute a symbol as an expression. |
| Function | execute |
Execute a named function or lambda function. |
| Function | execute |
Execute an expression that is contained in a string. This starts a sub-execution of a new script, but in the same context. |
| Function | execute |
Execute a symbol with a list of arguments. A symbol can be a function, a lambda function, or another (quoted) symbol. |
| Function | get |
Verify that an expression is a list and return an argument symbol, while optionally verify the allowed type(s) for that argument. |
| Function | join |
Join all symbols in an expression. |
| Function | parse |
Parse and validate a script in a context. |
| Function | result |
Return the SSymbol result from an argument symbol. |
| Function | run |
Run the script in the PContext instance. |
| Function | value |
Return the actual value from an argument symbol. |
| Variable | builtin |
Dictionary to map the interpreter functions to Python functions. |
| Function | __do |
Execute a symbol list. |
| Function | _do |
Return True if all of the arguments are True. The arguments can be a list of symbols. The type of all arguments must be Bool. |
| Function | _do |
Return True if any of the arguments is True. The arguments can be a list of symbols. The type of all arguments must be Bool. |
| Function | _do |
With the argv function one can access the individual arguments of a script. |
| Function | _do |
Assert a condition. If it fails an exception is raised and script execution interrupted. |
| Function | _do |
Base64-decode a string. |
| Function | _do |
Base64-encode a string. |
| Function | _do |
Execute a block of expressions. |
| Function | _do |
Just set and return a boolean value. |
| Function | _do |
Get the first symbol of a list without changing the list. |
| Function | _do |
The case function implements multiple test-action clauses. It evaluates a symbol and compares the result against multiple action lists based on the evaluation of that symbol. |
| Function | _do |
The CDR of a list is the rest of the list without the first symbol. The original list is not changed. |
| Function | _do |
Concat symbols together. |
| Function | _do |
The cons function creates a new list out of a first element (the car) and a second element (the cdr). |
| Function | _do |
This function returns the the current time (UTC-based) in the specified format. |
| Function | _do |
This function defines a new function. |
| Function | _do |
This function executes a code block for each element in a list. |
| Function | _do |
This function executes a code block a number of times. |
| Function | _do |
End script execution with an error. The optional argument will be assigned as the result of the script (pcontext.result). |
| Function | _do |
Evaluate a list as a function call. |
| Function | _do |
Enable or disable inline string evaluation. |
| Function | _do |
Filter a list based on a condition. |
| Function | _do |
This function defines an alias for a symbol. |
| Function | _do |
Retrieve an attribute from a JSON structure via a key path. |
| Function | _do |
Check whether an attribute exists in a JSON structure for a key path. |
| Function | _do |
Check whether an expression evaluates to true and then execute a symbol or list. Otherwise a second, optional symbol or list is executed. |
| Function | _do |
Check whether a symbol is contained in a list, or a string is contained in another string. |
| Function | _do |
Increment or decrement a variable by an optional value. |
| Function | _do |
Determine the index of a symbol or string in a list or string. |
| Function | _do |
Check whether a symbol, function, or variable is defined. |
| Function | _do |
Escape a string for use in a JSON structure. Newlines and quotes are escaped. |
| Function | _do |
Convert a JSON structure to a string. |
| Function | _do |
Define a nameless lambda function. |
| Function | _do |
Get the length of a symbol or list. |
| Function | _do |
Perform multipe assignments in sequence (let* function). |
| Function | _do |
Create a list out of the arguments |
| Function | _do |
Print a message to the debug or to the error log. Either the internal or a provided log function is used. |
| Function | _do |
Convert a string to upper or lower case. |
| Function | _do |
Apply a function to each element of a list or multiple lists, accumulating the result. |
| Function | _do |
Apply a regular expression to a string and return whether it matches. |
| Function | _do |
Get the minimum or maximum value of a list of numbers, strings or orher comparables. |
| Function | _do |
Boolean not operation. |
| Function | _do |
Get the nth element from a list, or the nth character from a string. The index is 0-based. |
| Function | _do |
Process various boolean and mathematical operations. |
| Function | _do |
Parse a string as executable code and return it for evaluation. |
| Function | _do |
Print the arguments to the console. |
| Function | _do |
Evaluate one or multiple symbols in a list. This is the explicite function that many |
| Function | _do |
End script execution. The optional argument will be assigned as the result of the script in the PContext.result attribute. |
| Function | _do |
Convert a symbol into a quotable version. |
| Function | _do |
Generate a random float number in the given range. The default for the range is [0.0, 1.0]. If one argument is given then this indicates a range of [0.0, arg]. |
| Function | _do |
Apply a function to each element of a list or multiple lists, accumulating the result. |
| Function | _do |
Remove an attribute from a JSON structure via its key path. |
| Function | _do |
Return from a function call or break from while loop. |
| Function | _do |
Return from a named block. |
| Function | _do |
Reverse a list or string. |
| Function | _do |
Return a number rounded to optional ndigits precision after the decimal point. |
| Function | _do |
Set an attribute of a JSON structure via its key path. |
| Function | _do |
Set a variable. The second symbol is automatically quoted, so it is taken as the variable name. |
| Function | _do |
Sleep for a number of seconds. |
| Function | _do |
Return a slice of a string or list. |
| Function | _do |
Convert a string that contains a JSON structure to a JSON dictionary. |
| Function | _do |
Convert a string to a number. |
| Function | _do |
Convert any symbol to its string representation. |
| Function | _do |
Convert a string to a symbol. |
| Function | _do |
Execute a cleanup form after the main form has been executed or in case of an error. |
| Function | _do |
URL-Encode a string. |
| Function | _do |
Provide a while loop functionality. |
| Function | _do |
Zip lists together. |
| Function | _utc |
Return the current time, but relative to UTC. |
| Function | _utc |
Return the current time's timestamp, but relative to UTC. |
| Variable | _on |
Name of the on-error function that is executed in case of an error |
PContext, symbol: SSymbol, length: int = None, minLength: int = None, maxLength: int = None):
¶
Assert that the symbol is a list of symbols, and that the list length is within the given arguments: either an exact length, or a minimum lenght and a maximum length.
All length parameter are optional. If none is given then no length check happens.
| Parameters | |
pcontext:PContext | The PContext object that represents the current script state. |
symbol:SSymbol | The SSymbol to check. It must be a list. |
length:int | Optional exact list length to assert. |
minint | Optional minimum list length to assert. |
maxint | Optional maximum list length to assert. |
| Raises | |
PInvalidArgumentError | In case any assertion fails. |
Check for script timeout.
| Parameters | |
pcontext:PContext | The PContext object to check. |
| Raises | |
PTimeoutError | In case the script timeout is reached. |
Recursively execute a symbol as an expression.
| Parameters | |
pcontext:PContext | The PContext object that represents the current script state. |
symbol:SSymbol | The symbol to execute. |
| Returns | |
PContext | The updated PContext object with the result. |
| Raises | |
PUndefinedError | In case a symbol is undefined. |
PInvalidArgumentError | In case an unexpected symbol is encountered. |
PContext, symbol: SSymbol, functionName: str, functionDef: FunctionDefinition | None = None) -> PContext:
¶
Execute a named function or lambda function.
| Parameters | |
pcontext:PContext | The PContext object that represents the current script state. |
symbol:SSymbol | The symbol to execute. |
functionstr | The name of the function that is executed. In case of a lambda this name is random. |
functionFunctionDefinition | None | The executable part of a function or lambda function. |
| Returns | |
PContext | The updated PContext object with the function result. |
Execute an expression that is contained in a string. This starts a sub-execution of a new script, but in the same context.
| Parameters | |
pcontext:PContext | Undocumented |
expression:str | String with list of symbols to execute. |
| Returns | |
PContext | PContext object. |
| Raises | |
PInvalidArgumentError | In case of an error. |
PContext, symbol: SSymbol, arguments: SSymbolsList = []) -> PContext:
¶
Execute a symbol with a list of arguments. A symbol can be a function, a lambda function, or another (quoted) symbol.
| Parameters | |
pcontext:PContext | The PContext object that represents the current script state. |
symbol:SSymbol | The symbol/function/lambda to execute. |
arguments:SSymbolsList | List of arguments to pass to the symbol. |
| Returns | |
PContext | The updated PContext object with the function result. |
PContext, symbol: SSymbol, idx: int | None = None, expectedType: SType | tuple[ SType, ...] | None = None, doEval: bool | None = True, optional: bool | None = False) -> PContext:
¶
Verify that an expression is a list and return an argument symbol, while optionally verify the allowed type(s) for that argument.
If any of these validations fail, an exception is raised.
This method also assigns a result and error state to self.
| Parameters | |
pcontext:PContext | The PContext object that represents the current script state. |
symbol:SSymbol | The symbol that contains an expression. |
idx:int | None | Optional index if the symbol contains a list of symbols. |
expectedSType | tuple[ | one or multiple data types that are allowed for the retrieved argument symbol. |
dobool | None | Optionally recursively evaluate the symbol. |
optional:bool | None | Allow the argument to be None. |
| Returns | |
PContext | Result PContext object with the result, possible changed variable and other states. |
| Raises | |
PInvalidArgumentError | In case of an error. |
PContext, symbols: SSymbolsList, parentSymbol: SSymbol, sep: str = ' ') -> PContext:
¶
Join all symbols in an expression.
| Parameters | |
pcontext:PContext | The PContext object that represents the current script state. |
symbols:SSymbolsList | A list of symbols to join. |
parentSSymbol | The parent symbol that will contain the result. |
sep:str | An optional separator for each of the stringified symbols. |
| Returns | |
PContext | The updated PContext object with the function result. The PContext.result attribute contains the joint string. |
PContext, symbol: SSymbol, idx: int | None = None, expectedType: SType | tuple[ SType, ...] | None = None, doEval: bool | None = True, optional: bool | None = False) -> tuple[ PContext, SSymbol]:
¶
Return the SSymbol result from an argument symbol.
| Parameters | |
pcontext:PContext | The PContext object that represents the current script state. |
symbol:SSymbol | The symbol that contains an expression. |
idx:int | None | Optional index if the symbol contains a list of symbols. |
expectedSType | tuple[ | one or multiple data types that are allowed for the retrieved argument symbol. |
dobool | None | Optionally recursively evaluate the symbol. |
optional:bool | None | Allow the argument to be optional. |
| Returns | |
tuple[ | Result tuple of the updated PContext object with the result and the symbol. |
PContext, arguments: list[ str] = [], isSubCall: bool | None = False) -> PContext:
¶
Run the script in the PContext instance.
| Parameters | |
pcontext:PContext | Undocumented |
arguments:list[ | Optional list of string arguments to the script. They are available to the script via the argv function. |
isbool | None | Optional indicator whether the script is called from another script. |
| Returns | |
PContext | PContext object with the result and the termination reason. |
PContext, symbol: SSymbol, idx: int | None = None, expectedType: SType | tuple[ SType, ...] | None = None, doEval: bool | None = True, optional: bool | None = False, default: Any | None = None) -> tuple[ PContext, Any]:
¶
Return the actual value from an argument symbol.
| Parameters | |
pcontext:PContext | The PContext object that represents the current script state. |
symbol:SSymbol | The symbol that contains an expression. |
idx:int | None | Optional index if the symbol contains a list of symbols. |
expectedSType | tuple[ | one or multiple data types that are allowed for the retrieved argument symbol. |
dobool | None | Optionally recursively evaluate the symbol. |
optional:bool | None | Allow the argument to be optional. |
default:Any | None | Optional default value to return if the argument is not found or is None. |
| Returns | |
tuple[ | Result tuple of the updated PContext object with the result and the value. |
PContext, symbol: SSymbol, doEval: bool = True, start: int = 0) -> PContext:
¶
Execute a symbol list.
This function is used internally by the interpreter.
| Parameters | |
pcontext:PContext | PContext object of the running script. |
symbol:SSymbol | The symbol to execute. |
dobool | Indicator whether to evaluate the arguments. |
start:int | The offset to start the evaluation. This is 1 for the _doProgn function and 0 for the interpreter. |
| Returns | |
PContext | The updated PContext object with the function result. |
Return True if all of the arguments are True. The arguments can be a list of symbols. The type of all arguments must be Bool.
Example
(any true false) -> false (any true true) -> true (any '(false false)) -> false (any '(true true)) -> true
| Parameters | |
pcontext:PContext | Current PContext for the script. |
symbol:SSymbol | The symbol to execute. |
| Returns | |
PContext | The updated PContext object. The result is either True or False. |
Return True if any of the arguments is True. The arguments can be a list of symbols. The type of all arguments must be Bool.
Example
(any true false) -> true (any false false) -> false (any '(false false)) -> false (any '(false true)) -> true
| Parameters | |
pcontext:PContext | Current PContext for the script. |
symbol:SSymbol | The symbol to execute. |
| Returns | |
PContext | The updated PContext object. The result is either True or False. |
With the argv function one can access the individual arguments of a script.
- Without an index argument this function returns the whole argument list, including the script name.
- If the index is 0 then only the script name is returned.
- Otherwise the nth argument is returned, starting with 1.
Example
(argv) -> The script name and all arguments (argv 3) -> The third script arguments
| Parameters | |
pcontext:PContext | Current PContext for the script. |
symbol:SSymbol | The symbol to execute. |
| Returns | |
PContext | The updated PContext object. |
| Raises | |
PInvalidArgumentError | In case of an error. |
Assert a condition. If it fails an exception is raised and script execution interrupted.
Example
(assert (< x 4))
| Parameters | |
pcontext:PContext | Current PContext for the script. |
symbol:SSymbol | The symbol to execute. |
| Returns | |
PContext | The updated PContext object. |
| Raises | |
PAssertionFailed | In case the assertion fails. |
Execute a block of expressions.
Example
;; Prints "Hello" and "World". The result is "World".
(block aSymbol
(print "Hello")
(print "World"))
;; Prints only "Hello". The result is 42.
(block aSymbol
(print "Hello")
(return-from aSymbol 42)
(print "World"))
| Parameters | |
pcontext:PContext | Current PContext for the script. |
symbol:SSymbol | The symbol to execute. |
| Returns | |
PContext | The updated PContext object. The result is the result of the last executed expression in the block, or the result of a matching return-from expression. |
The case function implements multiple test-action clauses. It evaluates a symbol and compares the result against multiple action lists based on the evaluation of that symbol.
The special symbol otherwise is the default case if no other action list matches the symbol.
Example
(case aSymbol
( 1 (print "Result: 1"))
( 2 (print "Result: 2"))
(otherwise (print "Result: something else")))
| Parameters | |
pcontext:PContext | Current PContext for the script. |
symbol:SSymbol | The symbol to execute. |
| Returns | |
PContext | The updated PContext object. The result result of the last executed action list, or NIL if nothing was matched and the otherwise symbol is not present. |
The CDR of a list is the rest of the list without the first symbol. The original list is not changed.
Example
(cdr '(1 2 3)) -> (2 3)
| Parameters | |
pcontext:PContext | Current PContext for the script. |
symbol:SSymbol | The symbol to execute. |
| Returns | |
PContext | The updated PContext object. The result is the rest of the list without the first symbol or NIL. |
Concat symbols together.
Though this function is mainly for concatenation strings, all types are supported. No space is added between the symbols, but the special symbol sp can be used to add a space character.
Example
(. "Hello" sp "world")
| Parameters | |
pcontext:PContext | Current PContext for the script. |
symbol:SSymbol | The symbol to execute. |
| Returns | |
PContext | The updated PContext object. The result is a new string. |
The cons function creates a new list out of a first element (the car) and a second element (the cdr).
It can be seens as the reverse of a car and a cdr function calls.
Example
(cons "a" "b") -> ("a" "b")
(cons "a" ("b" "c")) -> ("a" "b" "c")
(cons ("a" "b") "c") -> (("a" "b") "c")
| Parameters | |
pcontext:PContext | Current PContext for the script. |
symbol:SSymbol | The symbol to execute. |
| Returns | |
PContext | The updated PContext object. The result is a new list. |
This function returns the the current time (UTC-based) in the specified format.
This function has an optional format paramater that is the same as the Python's strftime* function. The default is %Y%m%dT%H%M%S.%f, which evaluates to an ISO8901 timestamp.
Example
(datetime) -> 20220107T221625.771604 (datetime "%H:%M") -> 13:31
| Parameters | |
pcontext:PContext | Current PContext for the script. |
symbol:SSymbol | The symbol to execute. |
| Returns | |
PContext | The updated PContext object. The result is a date time string. |
This function defines a new function.
A new function may have zero, one or multiple arguments. The result of the last executed expression in the function determines the function's result.
Example
(defun hello (name) (print (. "hello" sp name))) ;; define the function (hello "Arthur") ;; call the function
| Parameters | |
pcontext:PContext | Current PContext for the script. |
symbol:SSymbol | The symbol to execute. The function definition. |
| Returns | |
PContext | The updated PContext object. |
| Raises | |
PInvalidArgumentError | In case of a wrong definition. |
This function executes a code block for each element in a list.
The first argument is a list that contains the loop variable symbol and the list to loop over. An optional third argument is the result variable for the loop. The second argument is the code block to execute.
Example
(dolist (i (1 2 3)) (print i)) (dolist (i (1 2 3) result) (setq (+ result i))
| Parameters | |
pcontext:PContext | Current PContext for the script. |
symbol:SSymbol | The symbol to execute. |
| Returns | |
PContext | The updated PContext object. The result is the last executed code block or NIL. |
This function executes a code block a number of times.
The first argument is a list that contains the loop counter symbol and the loop limit. An optional third argument is the result variable for the loop. The second argument is the code block to execute.
Example
(dotimes (i 10) (print i)) (dotimes (i 10 result) (setq result i))
| Parameters | |
pcontext:PContext | Current PContext for the script. |
symbol:SSymbol | The symbol to execute. |
| Returns | |
PContext | The updated PContext object. The result |
End script execution with an error. The optional argument will be assigned as the result of the script (pcontext.result).
Example
(quit-with-error "Some error")
| Parameters | |
pcontext:PContext | Current PContext for the script. |
symbol:SSymbol | The symbol to execute. |
| Returns | |
PContext | The updated PContext object. |
| Raises | |
PInvalidArgumentError | In case of an invalid argument. |
PQuitWithError | In case the function quits successfully with an error. This is expected. |
This function defines an alias for a symbol.
An alias is a new symbol that points to an existing symbol. Aliased symbols can be aliases themselves.
The symbols must be quoted.
If the second symbold is not provided, then the alias is removed.
Example
(fset 'aSymbol 'anotherSymbol)
| Parameters | |
pcontext:PContext | Current PContext for the script. |
symbol:SSymbol | The symbol to execute. |
| Returns | |
PContext | The updated PContext object. |
| Raises | |
PInvalidArgumentError | In case of an error. |
Check whether an attribute exists in a JSON structure for a key path.
Example
(has-json-attribute { "a" : { "b" : "c" }} "a/b" ) -> true
| Parameters | |
pcontext:PContext | PContext object of the running script. |
symbol:SSymbol | The symbol to execute. |
| Returns | |
PContext | The updated PContext object with the operation result. |
Check whether an expression evaluates to true and then execute a symbol or list. Otherwise a second, optional symbol or list is executed.
Example
(if (< 1 2)
(print "true")
(print "false") )
| Parameters | |
pcontext:PContext | PContext object of the running script. |
symbol:SSymbol | The symbol to execute. |
| Returns | |
PContext | The updated PContext object with the operation result of the last operation in the executed list or symbol. |
Check whether a symbol is contained in a list, or a string is contained in another string.
Example
(in "Hello" "Hello, World") -> true (in a (b c)) -> false
| Parameters | |
pcontext:PContext | PContext object of the running script. |
symbol:SSymbol | The symbol to execute. |
| Returns | |
PContext | The updated PContext object with the operation result. |
Increment or decrement a variable by an optional value.
The default is 1.
Example
(setq a 1) (inc a 2) -> 3 (dec a) -> 2
| Parameters | |
pcontext:PContext | PContext object of the running script. |
symbol:SSymbol | The symbol to execute. |
isbool | None | Indicate whether to increment or decrement. |
| Returns | |
PContext | The updated PContext object with the function result. |
| Raises | |
PInvalidArgumentError | In case the variable is not defined, or the second argument doesn't evaluate to a number. |
Determine the index of a symbol or string in a list or string.
If the second argument is a string, then the first argument must also be a string.
Example
(index-of 1 '(1 2 3)) -> 0
(index-of "a" '("b", "c", "d")) -> nil
(index-of "b" "abc") -> 1
| Parameters | |
pcontext:PContext | PContext object of the running script. |
symbol:SSymbol | The symbol to execute. |
| Returns | |
PContext | The updated PContext object with the function result. |
| Raises | |
PInvalidTypeError | In case the first argument is not a string if the second argument is a string. |
Escape a string for use in a JSON structure. Newlines and quotes are escaped.
Example
(jsonify "Hello, World") -> "Hello\nWorld"
| Parameters | |
pcontext:PContext | PContext object of the running script. |
symbol:SSymbol | The symbol to execute. |
| Returns | |
PContext | The updated PContext object with the escaped JSON string. |
Define a nameless lambda function.
Example
((lambda (x) (* x x)) 5) -> 25 (setq y (lambda (x) (* x x))) ((y) 5) -> 25
| Parameters | |
pcontext:PContext | PContext object of the running script. |
symbol:SSymbol | The symbol to execute. |
| Returns | |
PContext | The updated PContext object with the lambda result. |
| Raises | |
PInvalidArgumentError | in case one of the arguments has the wrong type. |
Perform multipe assignments in sequence (let* function).
Note
Currently, assignment in parallel (let function) is not supported.
Example
(let* (a 1)
(a (+ a 1))) -> a = 2
| Parameters | |
pcontext:PContext | PContext object of the running script. |
symbol:SSymbol | The symbol to execute. |
sequential:bool | Indicator whether sequential (True) or parallel assignments shall be performed. |
| Returns | |
PContext | The updated PContext object with the function result and set variables. |
| Raises | |
PInvalidArgumentError | In case the format of the variable assignment is wrong. |
PContext, symbol: SSymbol, isError: bool | None = False, exception: Exception | None = None) -> PContext:
¶
Print a message to the debug or to the error log. Either the internal or a provided log function is used.
Example
(log "Hello, World")
| Parameters | |
pcontext:PContext | PContext object of the running script. |
symbol:SSymbol | The symbol to execute. |
isbool | None | Indicate whether this message will be logged as an error or a normal log message. |
exception:Exception | None | An optional exception |
| Returns | |
PContext | The updated PContext object with the function result. |
Convert a string to upper or lower case.
Example
(upper "Hello, World") -> "HELLO, WORLD" (lower "Hello, World") -> "hello, world
| Parameters | |
pcontext:PContext | PContext object of the running script. |
symbol:SSymbol | The symbol to execute. |
tobool | Indicator whether the conversion shall be to lower or upper case. |
| Returns | |
PContext | The updated PContext object with the function result. |
Apply a function to each element of a list or multiple lists, accumulating the result.
Example
(map (lambda (x y) (+ x y)) '(1 2 3) '(4 6 7)) -> (5 8 10)
| Parameters | |
pcontext:PContext | PContext object of the running script. |
symbol:SSymbol | The symbol to execute. |
| Returns | |
PContext | The updated PContext object with the function result. |
Apply a regular expression to a string and return whether it matches.
Note
The match function must be supplied to the interpreter.
Example
(match "aa" "a?") -> true (match "aa" "b*") -> false
| Parameters | |
pcontext:PContext | PContext object of the running script. |
symbol:SSymbol | The symbol to execute. |
| Returns | |
PContext | The updated PContext object with the function result. |
Get the minimum or maximum value of a list of numbers, strings or orher comparables.
Example
(min (1 2 3)) -> 1 (min 1 2) -> 1 (max (1 2 3)) -> 3 (max 1 2) -> 2
| Parameters | |
pcontext:PContext | PContext object of the running script. |
symbol:SSymbol | The symbol to execute. |
dobool | None | Indicator whether to get the maximum (True) or minimum (False) value. |
| Returns | |
PContext | The updated PContext object with the function result. |
Get the nth element from a list, or the nth character from a string. The index is 0-based.
Example
(nth 2 '(1 2 3)) -> 3 (nth 2 "Hello, World") -> "l"
| Parameters | |
pcontext:PContext | PContext object of the running script. |
symbol:SSymbol | The symbol to execute. |
| Returns | |
PContext | The updated PContext object with the function result. |
Process various boolean and mathematical operations.
The supported operations are:
- "<": smaller
- "<=": smaller or equal
- ">": greater
- ">=": greater or equal
- "==": equal
- "!=": unequal
- "or": boolean or
- "|": boolean or
- "and": boolean and
- "&": boolean and
- "!": boolean not
- "+": Addition
- "-": Substraction
- "*": Multiplication
- "/": Division
- "//": Division, rounding down and returning an integer number
- "**": Power
- "%": Modulo
The mathematical operations may have more then two arguments.
Example
(+ 1 2) -> 3 (+ 1 2 3) -> 6 (< 1 2) -> true
| Parameters | |
pcontext:PContext | Current PContext for the script. |
symbol:SSymbol | The symbol to execute. |
op:Callable | The operation to use. |
tp:SType | The expected result's data type. |
| Returns | |
PContext | The updated PContext object with the operation result. |
| Raises | |
PDivisionByZeroError | In case a division by 0 happens. |
PInvalidTypeError | In case one or more invalid types are provided for the operation. |
Parse a string as executable code and return it for evaluation.
Example
(eval (parse-string "(print "hello, world")")) -> prints "hello, world"
| Parameters | |
pcontext:PContext | Current PContext for the script. |
symbol:SSymbol | The symbol to execute. |
| Returns | |
PContext | The PContext object with the new symbol as result. |
Evaluate one or multiple symbols in a list. This is the explicite function that many
Example
(progn (print "Hello, World"))
| Parameters | |
pcontext:PContext | PContext object of the running script. |
symbol:SSymbol | The symbol to execute. |
dobool | Indicator whether to evaluate the arguments. |
| Returns | |
PContext | The updated PContext object with the function result. |
| Raises | |
PInvalidArgumentError | In case of an invalid argument or parameter. |
End script execution. The optional argument will be assigned as the result of
the script in the PContext.result attribute.
Example
(quit "some result") -> "some result"
| Parameters | |
pcontext:PContext | Current PContext for the script. |
symbol:SSymbol | The symbol to execute. |
| Returns | |
PContext | This function doesn't return anything, it always raises an exception. |
| Raises | |
PQuitRegular | Always raises this exception. |
Generate a random float number in the given range. The default for the range is [0.0, 1.0]. If one argument is given then this indicates a range of [0.0, arg].
Example
(random 1) -> 0.3 (random 2 3) -> 2.87
| Parameters | |
pcontext:PContext | Current PContext for the script. |
symbol:SSymbol | The symbol to execute. |
| Returns | |
PContext | The updated PContext object with the function result. |
Apply a function to each element of a list or multiple lists, accumulating the result.
Example
(reduce (lambda (x y) (+ x y)) '(1 2 3 4 5)) -> 15 (reduce '+ '(1 2 3 4 5) 10) -> 25
| Parameters | |
pcontext:PContext | PContext object of the running script. |
symbol:SSymbol | The symbol to execute. |
| Returns | |
PContext | The updated PContext object with the function result. |
Remove an attribute from a JSON structure via its key path.
One may remove multiple attributes at once by providing multiple key paths.
Example
(remove-json-attribute { "a" : { "b" : "c" }} "a/b") -> { "a" : {} }
| Parameters | |
pcontext:PContext | PContext object of the running script. |
symbol:SSymbol | The symbol to execute. |
| Returns | |
PContext | The updated PContext object with the operation result, ie a new JSON symbol. |
Return from a function call or break from while loop.
While returning it is possible to pass a return value.
Example
(return "some result") -> "some result"
| Parameters | |
pcontext:PContext | Current PContext for the script. |
symbol:SSymbol | The symbol to execute. |
| Returns | |
PContext | The updated PContext object with the function result. |
Return from a named block.
Example
(block "aBlock" 1 (return-from "aBlock" 2) 3) -> 2
| Parameters | |
pcontext:PContext | Current PContext for the script. |
symbol:SSymbol | The symbol to execute. |
| Returns | |
The updated PContext object with the function result. |
| Raises | |
PReturnFrom | Always raises this exception. |
Return a number rounded to optional ndigits precision after the decimal point.
If ndigits, the second parameter, is omitted, it returns the nearest integer.
Example
(round 1.6) -> 2 (round 1.678 2) -> 1.67
| Parameters | |
pcontext:PContext | Current PContext for the script. |
symbol:SSymbol | The symbol to execute. |
| Returns | |
PContext | The updated PContext object with the function result. |
| Raises | |
PInvalidArgumentError | In case of an invalid argument. |
Set an attribute of a JSON structure via its key path.
One may set multiple values at one by providing a list of (key/values).
Example
(set-json-attribute { "a" : { "b" : "c" }} "a/b" "d") -> { "a" : { "b" : "d" }
(set-json-attribute { "a" : { "b" : "c" }} '('("a/b" "d") '("a/c" "e"))) -> { "a" : { "b" : "d", "c" : "e"}
| Parameters | |
pcontext:PContext | PContext object of the running script. |
symbol:SSymbol | The symbol to execute. |
| Returns | |
PContext | The updated PContext object with the operation result, ie a new JSON symbol. |
Set a variable. The second symbol is automatically quoted, so it is taken as the variable name.
Example
(setq a "Hello, World") -> "Hello, World"
| Parameters | |
pcontext:PContext | Current PContext for the script. |
symbol:SSymbol | The symbol to execute. |
| Returns | |
PContext | The updated PContext object with the function result, ie the expression result. |
Sleep for a number of seconds.
This function can be interrupted when the script's state is set to any other state than running.
Example
(sleep 2.5)
| Parameters | |
pcontext:PContext | PContext object of the running script. |
symbol:SSymbol | The symbol to execute. |
| Returns | |
PContext | The updated PContext object with the operation result. |
| Raises | |
PNotANumberError | In case there is a problem with the number conversion. |
PInterruptedError | In case the sleep was interrupted. |
Return a slice of a string or list.
The behaviour is the same as slicing in Python, except that both start and end must be provided.
The first argument is the beginning of the slice, the second is the end (exlcuding) of the slice. The fourth argument is the list or string to slice.
Example
(slice 1 2 '(1 2 3)) -> (2) (slice 0 -1 "abcde") -> "abcd" (slice 99 100 '(1 2 3)) -> ()
| Parameters | |
pcontext:PContext | PContext object of the running script. |
symbol:SSymbol | The symbol to execute. |
| Returns | |
PContext | The updated PContext object with the function result. |
Convert a string that contains a JSON structure to a JSON dictionary.
Example
(string-to-json "{ "a": "b"")
| Parameters | |
pcontext:PContext | PContext object of the running script. |
symbol:SSymbol | The symbol to execute. |
| Returns | |
PContext | The updated PContext object with the operation result. |
| Raises | |
PInvalidArgumentError | In case the JSON input contains an error. |
Convert a string to a number.
Example
(string-to-number "1") -> 1
| Parameters | |
pcontext:PContext | PContext object of the running script. |
symbol:SSymbol | The symbol to execute. |
| Returns | |
PContext | The updated PContext object with the operation result. |
| Raises | |
PInvalidArgumentError | In case the input cannot be converted. |
Convert any symbol to its string representation.
Example
(to-string aSymbol) -> "[1, 2, 3]"
| Parameters | |
pcontext:PContext | PContext object of the running script. |
symbol:SSymbol | The symbol to execute. |
| Returns | |
PContext | The updated PContext object with the operation result. |
| Raises | |
PInvalidArgumentError | In case the input cannot be converted. |
Convert a string to a symbol.
Example
(to-symbol "aSymbol") -> aSymbol
| Parameters | |
pcontext:PContext | PContext object of the running script. |
symbol:SSymbol | The symbol to execute. |
| Returns | |
PContext | The updated PContext object with the operation result. |
| Raises | |
PInvalidArgumentError | In case the input cannot be converted. |
Execute a cleanup form after the main form has been executed or in case of an error.
Currently only programmatic flow interrupts are supported to trigger the cleanup form: assert, quit, quit-with-error, return, return-from.
Example
(unwind-protect
(print "main form")
(print "cleanup form"))
| Parameters | |
pcontext:PContext | Current PContext for the script. |
symbol:SSymbol | The symbol to execute. |
| Returns | |
PContext | The updated PContext object with the function result. |
Provide a while loop functionality.
Example
(setq i 0)
(while (< i 10)
((print i)
(inc i)))
| Parameters | |
pcontext:PContext | PContext object of the running script. |
symbol:SSymbol | The symbol to execute. |
| Returns | |
PContext | The updated PContext object with the operation result, ie the result of the evaluated expression or a return statement in the loop. |