FlxCode#
Fesslix comes with its own scripting language that can be used whenever a parameter/input of type FlxCode is required. For some time-critical operations, the internal scripting language can outperform code written directly in Python.
- type FlxCode#
{ OBJECT_1; OBJECT_2; ... OBJECT_N; }
- Description:
An expression of type FlxCode consists of a successive definition of objects of type
FlxObject, enclosed in curly braces.
The definition of an object starts always with the name of the object and ends always with a semicolon
;(see alsoFlxObject). Besides that, strict rules for the syntax of objects do not exist and, theoretically, each object can have its own syntax. However, most objects require first the definition of obligatory parameters and last the specification of optional parameters. In the object name uppercase and lowercase letters are not distinguished.The definition of an object can go over more than a single line. If a line break occurs within the definition of an object, it is simply ignored. Moreover, white-spaces are ignored as well.
Using an extended syntax, selected const-variables can be declared as local constants within the specified code-block:
{ OBJECT_1; OBJECT_2; ... OBJECT_N; }::{lc1,lc2,lc3}
where
lc1,lc2,lc3is a comma separated list of const-variables (i.e.,lc1,lc2,lc3have typeWord). Iflc1,lc2,lc3have not yet been declared, they are declared when the list is read. The const-variableslc1,lc2,lc3are treated as local: If their value changes within the specified code-block, the changes are reverted after{FLXCODE}is executed. An arbitrary number of const-variables can be defined as local.
Example:
As a simple introductory example, let us consider the object calc (we will only consider obligatory parameters here).
This object requires a FlxFunction as input and outputs the result of the evaluated function (it is the equivalent of the Python function flx.eval_fun()).
The following two definitions are equivalent:
import fesslix as flx
flx.load_engine()
flx.eval_code("""{
calc 1+55;
calc
1
+ 55
;
}""")
Random Number Generator: MT19937 - initialized with rand()=1322426257;
Random Number Generator: MT19937 - initialized with 1000 initial calls.
56 = 56
56 = 56
Note
Do not forget the curly braces ({ and }) at the beginning and end of the definition of FlxCode.
Working with FlxCode in Python#
- flx.eval_code()#
- Syntax:
flx.eval_code(expr)- Description:
Evaluates the expression expr.
- Parameters:
expr (
FlxCode) – The expression to evaluate.
Example:
flx.eval_code( """{
funplot pi;
const my_const = 5.12345;
}""" )
print( flx.eval_fun( "my_const" ) )
5.123449999999999
3.141593
Syntax of FlxCode#
Objects#
- type FlxObject#
- Description:
Contains an object in Fesslix.
This data type expects an object. For the definition of an object, not many rules adhere: (i) it must start with the respective name of the object, and (ii)it must end with a semicolon. Apart from these two rules, every object may have its own syntax. However, most objects first require the definition of obligatory parameters and, last, the specification of optional parameters.
Comments#
Comments are portions of the code that are ignored by the interpreter. They allow the user to make simple notes in relevant areas of the code. In Fesslix, comments are initiated by a sharp
#. The comment ends with the beginning of a new line.