next up previous contents index
Next: 5.6 Conclusion Up: 5.5.6 Tricks of Actions Previous: 5.5.6.1 Python Native Libraries   Contents   Index

5.5.6.2 Function Definition in SVM Models

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.


Table 5.1: An example of the textual representation of a function definition in a DCharts model
\begin{table}\begin{center}
\begin{minipage}{4.5cm}
\begin{verbatim}
STATECHAR...
...
O: print_a_to_b(1, 10)\end{verbatim}
\end{minipage} \end{center}
\end{table}


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.


next up previous contents index
Next: 5.6 Conclusion Up: 5.5.6 Tricks of Actions Previous: 5.5.6.1 Python Native Libraries   Contents   Index
Thomas Huining Feng 2004-04-28