Skip to content

Commit 96fc3e8

Browse files
committed
Add description of record constructors
This closes #60
1 parent 1148087 commit 96fc3e8

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

text/source/behavior/equations/record_def.rst

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,33 @@ The following are all examples of ``record`` definitions:
4747
Record Constructors
4848
-------------------
4949

50-
.. todo:: I need to fill this in
50+
.. index:: ! record constructor
5151

52+
Now that we know how to define a ``record``, we need to know how to
53+
create one. If we are declaring a variable that happens to be a
54+
``record``, the declaration itself will create an instance of the
55+
``record`` and we can specify the values of variables inside the
56+
record using modifications, *e.g.*,
57+
58+
.. code-block:: modelica
59+
60+
parameter Vector v(x=1.0, y=2.0, z=0.0);
61+
62+
But there are some cases where we might want to create an instance of
63+
a ``record`` that isn't a variable (*e.g.*, to use in an expression,
64+
pass as an argument to a function or use in a modification). For each
65+
``record`` definition, a function is automatically generated with the
66+
**same name** as the ``record``. This function is called the "record
67+
constructor". The record constructor has input arguments that match
68+
the variables inside the ``record`` definition and returns an instance
69+
of that ``record``. So in the case of the ``Vector`` definition
70+
above, we could also initialize a ``parameter`` using the record
71+
constructor as follows:
72+
73+
.. code-block:: modelica
74+
75+
parameter Vector v = Vector(x=1.0, y=2.0, z=0.0);
76+
77+
In this case, the value for ``v`` comes from the **expression**
78+
``Vector(x=1.0, y=2.0, z=0.0)`` which is a call to the record
79+
constructor.

0 commit comments

Comments
 (0)