As another trick, it is also possible to directly define functions in SVM models, though this method is highly discouraged because of its lack of modularity and portability. The initializer of a model is among the parts that allow arbitrary Python code. A model designer may decide to implement some of the functions in the initializer of a model. Because Python is an interpreted language, SVM is able to dynamically interpret the definition of those functions, and make them available for the actions executed later.
For example, the textual representation of the model in Table
5.1 defines a function print_a_to_b,
which prints integers from a to b to the console on a
single line. (a and b are integer parameters of the
function.) The model calls this function with a=1 and b=10
every 1 second with a timed transition. As a result, the user of the
model gets the following output in the console:
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
...
A whole Python library can be written under the INITIALIZER
descriptor. However, the more Python code is written here, the harder
it is to port the model to another simulator or executor, and the
harder it becomes to fully understand the meaning of the model. As
the size of the model grows, it becomes less manageable. The chances
of undetectable errors increase dramatically.