Functions in pen-script are objects with the attributes starting with ":". When writing a function in pen-script, Penbox will evaluate the function in real-time and replace the object with the result of the function.
This manual will discuss the following topics:
Operators
Return the sum of a list of values:
Returns the product of a list of values:
Returns the max of a list of values:
Also works with date formats
Returns the min of a list of values:
Returns true if the second value is higher than the first value provided in the list:
Logic
Evaluate expression in :if
. Return :then
if expression returns a trurthy value (eg: a string not empty is a truthy value), return :else
otherwise.
Evaluate a value and return the block associated with the value (in most language it corresponds to a switch):
Returns true
if the evaluated expression is defined (neither null nor undefined).
Example:
Compare a value with an other value using a function.
The list of possible functions:
:eq
compares if the two elements are equal:gt
compares if the first element is greater than the second one:ge
compares if the first element is greater or equal to the second one:lt
compares if the first element is lower than the second one:le
compares if the first element is lower or equal to the second one
Evaluate if a value is present in a list:
Evaluate if a list contains a value:
Evaluate of some elements from a list can be found in some elements from an other list:
Give the reverse boolean value of an expression:
Evaluate if an expression is true.
Evaluate if an expression is false.
Evaluate if all the expressions in the list return a truthy value
Evaluate if at least one of the expressions in the list return a truthy value
Returns the first undefined value of an list:
List & loops
Return a list of integer from index_start to index_end:
{":range": [4, 10]}
will return a value of [4, 5, 6, 7, 8, 9]
.Create an array with a specified length and optionally fill it using an expression.
:fill
context:@first:
boolean, true if first item@index
: current index, starting counting at 0@position
: current position. Equals to index + 1@last
: boolean, true if last item
Loop in a list and return an array evaluated for every element found.
:to
context:@item
: the content of the current item@first:
boolean, true if first item@index
: current index, starting counting at 0@position
: current position. Equals to index + 1@last
: boolean, true if last item
Objects
Based on the list of objects provided, overwrite the keys of the current object with the later.
Example:
Transform an object into a list with the input evaluated in ::as
. Optional argument ::order-by
with value key
or value
.
Example: