Multiple Return Values in Modelica
Modelica supports multiple return values through the use of tuples. This feature can be used to return both result and error values from a function.
In this Modelica code:
We define a function
vals()
that returns two integers using multiple output parameters.In the
main
function, we callvals()
and assign its return values toa
andb
using tuple assignment.We print the values of
a
andb
usingModelica.Utilities.Streams.print()
, which is Modelica’s equivalent to printing to the console.To demonstrate ignoring one of the return values, we call
vals()
again but only assign the second value toc
, effectively ignoring the first return value.Finally, we print the value of
c
.
When you simulate this model, it should produce the following output:
Note that Modelica is primarily used for modeling and simulation, so the concept of a standalone executable program is different from languages like Go. Instead, you would typically include this code as part of a larger model and simulate it using a Modelica simulation environment.