Water 5-Common Data Types-Generic Object and CollectionContract| Return type | wob | | No input parameters. | | Parameter kind | Default value | Type | | Other unkeyed arguments | opt with ekind of expression | wob | | Other keyed arguments | opt | | Water Contract<method set
_other_keyed=opt=wob=ekind.code="_add_to_environment"
_other_unkeyed=opt=wob=ekind.expression="_body"/> | |
See also: set_value, active_value
set is the main way to make an assignment, i.e. to assign a value
to a local variable or field.
set is similar to set_value but it can set multiple variables using the key=value syntax.
Example: Set a field in an object
thing.<set acolor="red" weight=2.<plus 3/> />
thing.acolor
 | "red" |
thing.weight
5 set with a regular object as _subject cannot have a content.
Set a Local Variable
set with no _subject can have a content. The variables will be local variables
and will be bound lexically during the execution of the code in the body of the set .
Example:
<set a=1 b=2> a.<plus b/> </set>
 | 3 |
If you do not give a content to a subjectless call to set, it will
set the given keys as local variables in the current lexical scope:
<method foo>
<set a=2 b=3/> a.<plus b/>
</method>
<foo/>
 | 5 |
Set a fluid variable
If _subject is fluid then the vars bound will be fluid vars and there must be a content.
During the dynamic extend of the execution of the content, (that means all the lexical code,
plus anything that it calls, recursively on down) the variable will be bound to the values
set. To reference them you must prefix the variable name with 'fluid'.
<method adjust factor=req> fluid.x.<times factor/> </>
fluid.<set x=5>
fluid.x.<plus <adjust 10/> />
</set> | 55 |
Which is equivalent to: fluid.x.<plus fluid.x.<times factor/>/>
which is:
5.<plus 5/>.<times 10/>
100
The secret is that fluid.x in the 'adjust' method executes to
5 even though it was set outside the body of the adjust method.
When our call to fluid.<set x=5> x </set> returns, then
the value of fluid.x is changed to what it was before the call to
fluid.<set x=5> x </set>
which will be unbound if we hadn't previous wrapped the dynamically
executing code in fluid.<set x=foo> x </set>
Thus each call to fluid.<set x=foo> x </set> will shadow the previous value of fluid.x
until the call to set returns.
The Returned Value
set returns _subject i.e. the container which has the variable being set.
If there is no subject and no content, set returns null.
Example: when setting local variables, set returns null
<set a=2 b=3/>
null
If there is a content, set returns the value of the last expression.
Example:
<set a=2 b=3> b a </>
2 Example:
fluid.<set a=2 b=3> fluid.b fluid.a </>
 | 2 |
© Copyright 2007 Clear Methods, Inc.