Parameters, properties, arguments¶
Goals, transforms and needs give us the expressiveness to build a complete specification. However,
sometimes, variables need to be available outside a component's own definition. For instance,
when we imposed the min-water-flow
design requirement, we could not yet link it to the water-flow
inside the pump
component.
Just as well, we would like both the pump
and drive-mechanism
to work with the same torque
variable, instead of each having their own unique variables. That way we can check whether the
requirements that all components impose on a variable are carefully captured and coordinated.
To indicate the owner of a certain design variable, you can add the property
keyword to the
parameter declaration.
Parameters¶
Let's review the CentrifugalPump
's definition. It now has a parameters
section:
world.esl | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
|
So instead of the earlier "variables", it now has "parameters". Parameters of a definition are the variables that are expected to be supplied as arguments when you create an instance of the definition.
Properties¶
We also added a dimension parameter, length
. The property
keyword is added to this parameter, as
this is a typical characteristic of the drive mechanism component.
Warning
Note that by definition flows cannot be properties of components as they flow through the
system. As such, no single component owns a flow. Flows are variables that are involved in
goal-
or transformation-requirements
and constraints
. The flows in this definition are
the torque
and water-flow
.
Arguments¶
The definition of parameters means that the instantiation of the components living in the world
has also changed. The parameters you set in a definition are required to be provided at each
instantiation. Let's review this for the pump
component instance:
world.esl | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
|
Here, the required parameters of the CentrifugalPump
definition are provided by means of the with
arguments
keywords followed by an argument list.
This list is positional, meaning that the arguments are mapped to the parameters by the order in which they are defined and provided.
An argument list may be of the inline form foo is a Foo with arguments bar, baz, quux
or the
multi-line form as shown in the snippet: using an asterisk (*
) list.
Note
Note that we do have to specify the spatial
type both at the world level and in the
CentrifugalPump
's parameters. The compiler will alert you if any type
mismatches are found between parameters and the provided arguments.
Parameters versus arguments¶
We use parameters
in definitions and (with
) arguments
in instantiations. This distinction is
often encountered in programming languages and to translate
Robert Nystrom's1 excellent definition to our terminology of 'definitions'
and 'instantiations':
- An argument is an actual variable representing a value you pass to an instantiation when you call it. So an instantiation call has an argument list. Sometimes you hear actual parameter used for these.
- A parameter is a variable that holds the value of the argument inside the body of the definition. Thus, a function declaration has a parameter list. Others call these formal parameters or simply formals.
Next!¶
Press next (or N on your keyboard) to head over to the next page! P is for Previous.
-
R. Nystrom. Crafting Interpreters. Genever Benning, 2021. ISBN 9780990582939. ↩