Water 5-Syntax and Fundamentals-Variable: Local and FieldContract| Return type | wob | | Parameter key | Default value | Type | | place | req | | new_value | req | | Water Contract<method set_value
place =req
new_value=req/> | |
See also: set, active_value
Note that normally 'set' is used instead of set_value.
Use set_value only when you want the key that is to be set to be computed.
Please read the documentation on 'set' before reading about set_value.
The first argument is the place to set, the second is the new value.
Both arguments are executed.
<set_value place new_value/>
Local variables:
<set_value "foo" 1.<plus 2/> />
foo
 | 3 |
foo will be bound until the end of the method body that its in.
If we've called execute_string on a string that has several top level
expressions, then foobar will be bound throughout, i.e. one local environment
for the entire string.
Field Variables:
thing.<set_value "foo" <thing/>/>
thing.foo
 | <thing/>
|
thing.foo.<set_value "baz" 2/>
thing.foo.baz
 | 2 |
Below here are advanced uses of set_value not needed for simple programming.
These take advantage of the fact that set_value sets a key that is the result
of executing its first argument.
Computing Place
thing.<set_value "my".<join "place"/> "red"/>
thing.myplace
 | "red" |
Fluid Variables:
Fluid variables can be set by calling set_value with a _subject of fluid.
Unlike local variables, they have DYNAMIC extent.
Fluid variables shadow previously set stack variables.
In the example below, we set up two (nested) fluid variables each named test7.
For the execution of the BODY of the inner set, the inner $test7 i.e. the one
with value 77, shadows the one with value 777.
When the inner set is called, first test7 and 77 are pushed onto the fluid variable "stack",
then the content of the set is executed. First we call the method test_meth2
which causes test_meth to be called, which executes the fluid variable test7,
whose value is looked up on the stack to get 77 which is returned by
both methods and ultimately by the inner set then finally the outer set.
Example:
<method test_meth2> <test_meth/> </>
<method test_meth> fluid.test7</>
fluid.<set test7=777>
fluid.<set test7=77>
<test_meth2/>
</set>
</set> | 77 |
You can test that a fluid variable existis by using has just as in any other object:
fluid.<set test8=88>
fluid.<has "test8"/>
</set>
 | true |
You can compute the name of a fluid to set. Here's a rather tricky example:
<set myvar="foo97">
fluid.<set_value myvar 4>
fluid.<get myvar/>
</set_value>
</set> | 4 |
First the local variable myvar is bound to "foo97".
Next in our call to set_value we use the value of myvar, i.e. "foo97"
as the name of the fluid variable to set to 4.
Finally within the content of call to fluid.set we execute the expression
fluid.<get myvar/>
which is effectively fluid.foo97 , whose value is 4 .
© Copyright 2007 Clear Methods, Inc.