@@ -47,5 +47,33 @@ The following are all examples of ``record`` definitions:
47
47
Record Constructors
48
48
-------------------
49
49
50
- .. todo :: I need to fill this in
50
+ .. index :: ! record constructor
51
51
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