Water 5-Meta Programming-ExecuteContract| Parameter key | Default value | Type | | source | opt | | returns | "first" | string | | Water Contract<class expression
source =opt
returns="first"
/> | |
To create expressions programmatically (programs that write programs)
The expression:
foo.baz.bar.<buy yum x=10/>
can be created using:
<set e=expression/>
<e.path <e "foo.baz"/> <e.var "bar"/> <e.call "buy" <expression.var "yum"/> x=10/> />
To create an expression from a string:
<expression "foo.bar.<buy x=10/>"/>
In normal processing, Water takes a string of source code, parses the string
into a expression objects, then executes each expression to create
resulting value objects.
Many other languages such as C, Java, and JavaScript don't have the
concept of expressions.
In Water, you rarely deal with expressions directly. They are an intermediate
data representation that is created temporarily during the process of executing a string.
However, Water enables you to create expressions, pass them around, and eventually
execute them, perhaps multiple times. This is very useful for creating a program
that writes code.
Certain key primitive expressions are created by the Water parser and are
"self executing", that is, executing these expressions just returns the expression
themselves. These are: integers, floats, booleans, characters, strings and null.
Non self_executing expressions are: variables, calls, and paths.
Other data such as vectors and "records", regular objects are usually not
passed to the evaluator, but if they are, they are just returned as is, i.e.
they are "self executing".
<expression "34"/>
34 <expression <string>"some text"</string> />
 | "some text" |
Example: returns an expression variable with the name "foo"
<expression "foo"/>
Returns a path of two parts, the integer 3 and a call expression to the method plus .
<expression "3.<plus 4/>"/>
<expression <join "foo" "bar"/>/>
returns a variable expression of name "foobar".
A given string might contain the source for one or more expressions.
expr takes a parameter to tell it whether to return the first expression
in the string or a vector of all the expressions in the string.
returning the first expression is the default.
<expression "23 45 67"/>
23 <expression "23 45 67" returns="first" />
 | 23 |
<expression "23 45 67" returns="all"/>
 | <vector 23 45 67/>
|
a vector of the three integers.
© Copyright 2007 Clear Methods, Inc.