WaterDoc: thing.active_value - a defclass
Contract <active_value />
Tests
More...
<defclass boat weight=100
                      total_weight=<active_value>
                                     _subject.weight.<plus 1/>
                                    </>
      />
      <set my_boat=<boat weight=127/> />
      my_boat.total_weight
result=128
<defclass boat weight=100 total_weight=111/>
        <set my_boat=<boat weight=127/> />
        my_boat.<set total_weight=<active_value>
                                  _subject.weight.<plus 100/>
                                 </>
        />
        my_boat.total_weight
result=227
You can set a variable such that instead of just returning the value in the field, it will execute arbitrary code instead.
Example:
thing.<set test_av=
     <thing head_weight=200
           tail_weight=300
           weight=<active_value> thing.test_av.head_weight.<plus thing.test_av.tail_weight/>
                  </active_value>
     /> />
Example: thing.test_av.head_weight result=200
Example: thing.test_av.tail_weight result=300
Example: thing.test_av.weight result=500
Example:
thing.test_av.<set head_weight=222/>
Example: thing.test_av.weight result=522

You can also set local and stack variables to active values.
When a call to active_value is executed, a special object is created that captures both the expressions in the content of the call as well as the local environment that the call was made in. So the content of active_value can contain references to local variables in the environment of the call. When a references to a variable that contains an active value is made, the expressions in the content of the creating make-active_value are executed in their original local environment.
We can use active_value to set up an "alias" like so:
Example:
thing.test_av.<set orig=27/>
thing.test_av.orig
result=27

Example:
thing.test_av.<set clone=<active_value> thing.test_av.orig</active_value> />
thing.test_av.clone
result=27

Example:
thing.test_av.<set orig=28/>
thing.test_av.orig
result=28

Example: thing.test_av.clone result=28

regardless of which one(s) are set to what, both will have the same value.
Within the body of active_value, "_subject" refers to the object that was called with the make active value. For example:
Example:
<defclass boat hull_weight=10 sail_weight=20
               total_weight=<active_value>
                              _subject.hull_weight.<plus _subject.sail_weight/>
                            </active_value>
/>
<boat sail_weight=40/>.total_weight
result=50

Here's why: First an instance of boat is created, shadowing the sail_weight from boat of 20 with 40. Then we ask for the total_weight where we get the hull_weight from boat because it isn't shadowed (10) and the sail_weight from the instance (40) for 10 + 40 = 50
Free local variables in the content of a call to active_value will execute to the values that they had when the call to active_value was made, just like a closure.