Water 5-Method and Class-Method
class and type method
Contract
Return typewob
No input parameters.
Parameter kindDefault valueType
Other unkeyed argumentsopt with ekind of expression
Other keyed argumentsopt with ekind of expression
Preconditiontrue
Water Contract
<class method
  _name_argument=req=wob=ekind.expression
  _container    =wob
  _body         =opt=vector
  _return_type  =wob
  _other_keyed  =opt=wob=ekind.expression=wob="_add_to_environment"
  _other_unkeyed=opt=wob=ekind.expression=wob="_body"
/>

See also: class, return


method is a class in Water used to package up a sequence of expressions to execute later. Like other classes, a call to method creates a new method and returns it. A side effect is that a field in the container of the method having the key of the name of the method, is set to the new method object.
Below we define the method foo to take one required argument, a and one optional argument b with a default value of 0 .
Since the name of the method is just a symbol, the container of the method will be wob . wob.foo will execute to our new method object. We call the method via <foo 3 5/> which causes a and b to become local variables set to 3 and 5 respectively, then the body of the method, <vector a b/> is executed. a executes to 3, b executes to 5, and the call to vector creates a vector of two values, 3 and 5.
The last expression executed in a body of a method has its value returned by a call to the method, so <vector 3 5/> , being the one and only expression in the body, has its value returned.
<method foo a=req b=0> 
    <vector a b/> 
</method>
<foo 3 5/>
<vector 3 5/>

Below we show foo called with just one argument. The value of b will default to 0. Note that for the result we are using "v" as a synonym for vector. Water has few synonyms, but this one is so common we employ it to be more concise.
<foo 4/>
<v 4 0/>

You can also pass arguments by key instead of by-position as we have done above. This is more verbose, but provides better documentation of the call and allows you to pass arguments in any order. That is particularly useful when you have multiple optional arguments in the method but only want to pass some of the later ones explicitly, while allowing the earlier ones in the parameter order to default.
<foo b=9 a=2.<times 4/>/>
<v 8 9/>

Water methods have tremendous versatility. The rest of this documentation describes the details for utilizing the versatility. If you understand the above examples, you can get started defining and calling methods, and use to the material below for reference.

Method Class

Methods are objects as is everything else in Water. The class/parent of the method object is method
<method foo/>._parentmethod

a wob
Parameter keyDefault valueType
_name"method"string
The first argument is the name of the method. In the simplest case when the method name is just a symbol, it becomes a field key in wob whose value is the new method object. It also becomes the value of the _name field in the new method. Below, foo gets the method object itself. ._name extracts the value of the _name field from that object.

<method foo/>
wob.foo._name
"foo"

Methods have containers. Those are the objects (usually classes) that have a field whose key is the name of the method and whose value is the method object itself. Above, the container for our 'foo' method is wob. Thus exectuing <method foo/> creates a field in wob named "foo" with the value of our new method object.
The next example is the same as the previous example except that we have chosen a container besides "wob" for our method. We are still creating a new field in the container named "foo" to have the value of the new method. But instead of "wob" being the container, "temp" is the container. temp is a field under wob used to stick temporary stuff when you've got no better place to put it, similar to "temp" folders in file systems.
Note that since both this definition and the above have an empty body, calling either method returns null.
<method temp.foo/>
temp.foo._name
"foo"

You can make an "anonymous" method when you do not require a specific method name by using a name of null.
<method null> 123 </>
This call to method returns a method that, when called, returns the number 123. If you want to use this method you must save it in a variable as in:
<set xxx=<method null> 123</>>
    <xxx/>
  </set>
123
or use it immediately in a call such as:
<<method null> 123</>/>123
or pass it to another method that might call it.
Anonymous methods have no container and no name. Sometimes you want to create a method that has no container bcuse you don't want it referenced by anyting else, but you might want to give it a name for doccumentation and debugging purposes. We can do that like so:
<method null.my_meth> 123</method>
igonre

a wob
Parameter keyDefault valueType
_containerwob
Rarely do you specify he container of a method explicitly. The most common way to specify a container for a method is to put the call to method inside the body of a call to class like so:

<class boat>
    <method launch> xxx </method>
  </class>

This will make a field inside the new 'boat' class named 'launch' whose value will be the method object. Since a call to class returns the new class, just like a call to method, we can do the below to verify the above.
<class boat>
  <method launch> xxx </method>
</class>.launch._name
"launch"

The second most common way to specify the container of a method is to have a top level call to method, but give the container explicitly as a prefix to the name of the method like so:
<method boat.skuttle> yyy </method>
boat.skuttle 

Using this form we don't have to modify the source code for the boat class, we can just extend it from any file. Note that we can now execute boat.skuttle to get our new method object.
Significantly less common that either of the above ways to specify the container is to use the _container parameter explicitly. this will override whatever container has been specifed due to the class wrapper or the method name.
<method decommission _container=boat/>
boat.decommission 

Since the value of _container is just executed, it can be any water expression. Here we give an instance of boat a method that the other instances will not share.
<method paint_it _container=<boat/>> .<set color="blue"/> </method>
false.paint_it 

The above doesn't make a whole lot of sense because our new instance of boat, created with <boat/> isn't saved anywhere so it will just be garbage collected. But you can create it, save it in some container and then use it as the value of _container.
Being able to give instances their own custom fields, including fields containing methods, is a flexibility Water does not share with other popular languages.

Method Parameters

You can define as many parameters to a method as you like. Each parameter must have a name and a 'default value'. There are several optional parameter characteristics as well. The syntax for specifying them is: name=default_value=type=ekind with everything after the default_value being optional.
You can also define methods that can accept any number of unkeyed arguments (using the special parameter name of _other_unkeyed), as well as any keyed parameters (using the special parameter name of _other_keyed), even though those keys aren't mentioned in the known parameters when defining the method.

Parameter Names

The first parameter characteristic is the parameter name. It must be a symbol.
<method foo p1=req> p1 </>
<foo 27/>
27

Our call of <foo 27/> causes p1 to be bound to 27, then the body of the method is executed. In this case, that is just p1 so 27 is returned from the call.

Parameter Default Values

The second parameter characteristic is default value. It must be present. If we do not pass in an arg that has a default value, the variable takes on the value of the default value defined in the call to method.
<method foo p1=78> p1 </method>
<foo/>
78

The default value is actually code that is executed when the method is called without the specified argument. The code is executed in the environment of the method definition. It may not contain references to other parameters of the same method call.
<method foo p1=<plus 2 3/> >
   p1
 </method>
<foo/>
5

If you want to make an argument optional but don't have a predefined default value, you can use opt.
<method foo p1=opt> p1 </method>
<foo/>
opt

Another special default value is req indicating that the argument is required. If the required arg is not passed in a call, the call will error.
<method foo p1=req> p1 </method>
<foo/>
error

When defining a number of parameters in a call to method, all of the required parameters must come before the first optional parameter.
<method foo a=req b=req c=3 d=4>
     <vector a b c d/> 
  </method>
<foo 1 2/>
<v 1 2 3 4/>

Parameter Types

To indicate a type for a parameter you must specify it as the third parameter characteristic like so:
<method foo p1=78=integer />
This example indicates that the value passed in for this parameter must be an integer. The parameter type will not actually be used to verify the types of arguments unless you turn on "Type Checking" (See the IDE Options menu). Even if you don't turn on type checking, it is a good idea to specify the type of each parameter for documentation purposes. Parameter type defaults to wob meaning that it can take any type.

Parameter Ekinds

Ekind is a short name for "Execution Kind" The execution kind of the parameter determines how the argument will be processed at the time of the method call. Note that other languages do not have ekinds. Some of the functionality of ekinds can be obtained in Lisp's macros, though those are more cumbersome to use than Water's ekinds.
The possible ekinds are:

ekind.code

(the default) During a method call, the source code of the argument is read and executed before being passed to the method. This is the functionality of method calls in all popular programming languages. But this does not allow code to be passed into a method for later execution. That means you cannot write control structures or methods that take code as arguments to manipulate programmatically.

ekind.expression

The source code of the argument is pased but not executed before being passed to the method. An expression such as a variable, a path, a call, a number, a string, or a boolean will be passed into the method.

ekind.string

The source code is not read or executed but is just passed in as a string. When using "ek_string" as an execution kind, be aware that for an "attribute" arg, that is any arg that is not the content arg, when passing in a value, the actual source code string for the arg must be a valid Water expression.
<method foo arg=req=wob=ekind.string> arg </>
<foo some_var/>
"some_var"
Notice in the example above that the string "some_var" is returned. some_var is not executed, so it does not matter if it is defined or not. In fact, if we have the normal ekind of ekind.code:
<method foo arg=req=wob=ekind.code> arg </>
<foo some_var/>
error
we get an error. Note that arg=req=wob=ekind.code is the same as arg=req since the type and ekind default to wob and ekind.code. When using ekind_string args, the args you pass in have to be able to be read by the reader as one expression. For example, using our definition of foo above, the use of "don't" without the double quotes as the arg to foo would error since the reader would see the single quote but not a matching double quote. We could, however use "don't" with the double quotes in the source for the arg. The string value of the arg would be seven chars long, and start and end with the double quote char.
When you make the ekind of _other_unkeyed be ekind.string, the entire content area of the call is treated as the string,. In this case we can stick in an unbalanced apostrophe. Note that the spaces before and after the word are also captured in the string.
<method foo2 _other_unkeyed=req=wob=ekind.string> _other_unkeyed.0 </>
<foo2> a string </foo2>
" a string "
ekind.string can be used for conditionally executing a string.
<method execute_strings_starting_with_open_angle arg=req=wob=ekind.string>
       <if> arg.0.<is <char "<"/>/>  <execute source=arg/>
            else arg
       </if>
    </method>
<execute_strings_starting_with_open_angle <minus 7 2/>/>
5
<execute_strings_starting_with_open_angle junk/>
"junk"
<execute_strings_starting_with_open_angle 3.14/>
"3.14"
In our first example above, we get the result of five because the string in arg starts with an open angle so execute is called on it. In the second example, since our string does not start with an open angle, the arg is returned unexecuted so we get the string "junk". In the third example, we also don't execute the argument. But note we don't even parse it, so rather than get a double floating point number, we get just a four-character string. Later on, if you wanted to convert that string to a number, you could call execute on it.
<execute source="3.14" />3.14

If you don't think you have a use for this functionality, you are thinking like a traditional programmer. You can write lots of great code without using these kinds of features but in certain situations, such power becomes extremely handy. If you're aware of this functionality, you will begin to notice those situations.

ekind.mixed

ekind.mixed is used only for the _other_unkeyed parameter. It grabs the _other_unkeyed as a vector of strings and objects. All the text before the first open angle bracket will become the first element of the vector as a string. It is not read or executed. The source from the first open angle to the closing angle will be read and executed. The result will become the next element of the vector. Each successive string or call will be treated as a string or code to be executed.
<method foo _other_unkeyed=opt=wob=ekind.mixed> _other_unkeyed</>
<foo>computations <plus 2 3/> mixed with text <times 4 5/></foo>
<vector "computations " 5 " mixed with text " 20/>
The result is a vector of four elements. The first and third are strings, and the second and fourth are computed integers.
As you might have guessed, ekind.mixed is ideal for hypertext that contains text and mark up. Water has defined all xhtml tags as Water classes. Calling <b>hey</b> creates an instance of the "b" class. b is defined by <class b _other_unkeyed=opt=wob=ekind.mixed/> so that a call to b treats its content area as hypertext. All other xhtml tags are defined similarly so that you can make deeply nested web pages that treat the "text" as just text but execute the tags. The hypertext tags stick the elements of the _other_unkeyed vector up into the instance of the tag itself so:
<b>hey<i>you</i></b>.0"hey"
<b>hey<i>you</i></b>.1
<i>
you</>
<b>hey<i>you</i></b>.1.0"you"

ekind.xdata

This ekind is used in situations where you want to make objects out of tags that are not defined. For example, you can use it to execute a file of XML with tags that are not defined in Water to create a nested Water object. ekind.xdata is similar to ekind_expression in that it doesn't execute the code but does parse it and put it into objects. However, the objects are more useful as real objects than the expression objects that are used by the evaluator and are not cluttered with refernces to the source that they were parsed from.
xdata does different things depending on whether the code being parsed as xdata is in an attribute or the content of a tag. Here's an example:
<execute source=
  '<boat color=blue size="4" weight=123  material=<wood/>> 56 78 sail <nylon/></boat>'
   a_ekind=ekind.xdata/>
data.<call _method="boat" color=<symbol name="blue"/> size="4" weight=123 material=data.<call _method="wood"/> " 56 78 sail " <data.call _method="nylon"/>/> 

Let's analize this in detail. We are making a call so we return an instance of data.call. The call has a parameter named "_name" whose value is the string of the name of the method or class of the call. Note that 'boat" need not exist when we execute this test. Next we have our 'color' parameter whose value is 'blue'. Had we used ekind.code 'blue' would be executed an if there was no binding for it, the system would error. Here we don't attampt to look for a binding of 'blue', we just create a symbol named 'blue'.
Next the size parameter has a value of a string. We use the string as is in the output. i.e. a string of one character, 4, is created. Next the weight parameter is passed 123 from which we create the integer 123. Had we wrapped quotes around 123 in the input, we would have gotten a string on the output just as with size above.
Next the parameter wood has a call so we make a call out of it, jsut as we do for the outer call of 'boat'.
Now we process the content of the call to boat. This is procesed similarly to hypertext with the difference that the calls are made into data.call instances and are not executed. So we chop up the source of the content into calls and the strings that are between the calls. We have two elements in the content of this call, " 56 78 sail " and <nylon/> so we make a string of the first element and a data.call of the 2nd. These new values are stuck into the 'vector_fields" of our data.call for boat. That means they are made the values of the field 0 and 1. From teh returned value we can access them using the_val.0 and the_val.1 Here's another way we can invoke the xdata execution kind. We make a method whose _other_unekeyd ekind is ekind.xdata. This method is simply returned the vector that is the value of _other_unkeyed when the method is called. We can call the method with any argumetns that are syntactically valid. They will not be executed however, just made into xdata and returned.
<method foo _other_unkeyed=req=wob=ekind.xdata> _other_unkeyed </method>
<foo 123 bar "baz" <junk/>/>
<vector 123 <symbol name="bar"/> "baz" data.<call _method="junk"/>/>
Since we are only passing "attributes", the xdata attribute rules apply as opposed to the xdata content rules.

ekind.bytes

Sometimes you need to create a string of an arbitrary sequence of characters. If you just type in the characters, you still need to delimit the string. In Water if the characters don't include double quote chars, you can use double quotes to delimit the string. "hey there" If they DO use double quote chars, but don't use single quote chars, you can use single quote chars to delimit the string. ''hey "over" there' If they use both, you can ESCAPE the quoting chars as: "hey "over" there's" But what if you don't want to escape those chars because there are many of them, or you are grabbing the data from somewhere else or whatever? In these unusual situations, ekind.bytes becomes handy. It lets you place an arbitrary sequence of chars into a string.
<method foo66 _other_unkeyed=req=wob=ekind.bytes> _other_unkeyed </method>
<foo66>stuff</foo66>.0
"stuff"
So far that's not different from ekind.string. But suppose you want to have the char sequence &lt;/&gt; in your string? First of all, ekind.bytes can only be used for the _other_unkeyed parameter. Second, when it is used, you must use a full ending tag, ie </foo> and not &lt;/&gt; . With these restrictions:
<foo66>more&lt;/&gt;stuff</foo66>
<vector "more</>stuff"/>
Normally <foo>more</> would be a full call, but because we've defined foo's _other_unkeyed to be ekind.bytes , the call continues on to the full closing tag of foo.
But suppose we want to have a full closing tag for foo in our string? In that case, this call to foo will not help, but there's another way around it. The special method bytes lets you have a full ending tag within it as long as you specify the length of the content.
<bytes ends_at=10>a</bytes>z</bytes>.0
"a</bytes>z"
See the documentation for bytes for more features.

Mixing ekinds

Since ekinds are indicated for each parameter, you can define methods that use many of them at once. You can only use hypertext and bytes on _other_unkeyed , but the other ekinds can be used anywhere.
<method foo4 p1=req=integer=ekind.code p2=req=wob=ekind.string 
                  _other_unkeyed=opt=wob=ekind.mixed>

      <vector p1 p2 _other_unkeyed/>
    </method>
<foo4 2.<power 2/> is> equal to <times 2 2/> and <plus 2 2/></foo4>
<vector 4 "is" <vector " equal to " 4 " and " 4/>/>

a wob
Parameter keyDefault valueType
_other_unkeyedopt with ekind of expression
_other_unkeyed is a special arg that, if a method is defined to take it, collects all the args after the last defined named parameter into one vector.

2.<plus 3 4/>9
If a _other_unkeyed argument is allowed, we can also pass it in as a vector by naming the argument in the call like so:
2.<plus _other_unkeyed=<vector 3 4/> />
9
And we can combine both techniques.
2.<plus _other_unkeyed=<vector 3 4/> 5 6/>
20
To define a method that takes _other_unkeyed arguments, just make one of its arguments _other_unkeyed.
<method foo6 weight=req _other_unkeyed=req>
    _other_unkeyed.1
  </>
<foo6 32 42 52 62/>
52
because while executing the code of foo, the local variable _other_unkeyed is bound to an object that has fields of: 0=42, 1=52, 2=62. So _other_unkeyed.1 is 52. Note that 32 is bound to weight. When there are both required parameters and _other_unkeyed, the position-passed arguments map to the required arguments. If there are any additional position-passed arguments, then they will be put in the _other_unkeyed object. Methods that take optional arguments as well as _other_unkeyed arguments will bind the non-required position-passed arguments to _other_unkeyed, not to the optional args. To pass an optional arg to a method that takes _other_unkeyed, you must pass it by keyword.
<method foo6 weight=req height=22 width=33 _other_unkeyed=opt>
     <vector weight height width _other_unkeyed.0 _other_unkeyed.1/>
   </method>
<foo6 100 200 300 400 500 600/>
<vector 100 22 33 200 300/>
because height and width use their default values, whereas
<foo6 100 height=200 width=300 400 500 600/>
<vector 100 200 300 400 500/>

Naming the _other_unkeyed local variable

After the ekind in a parameter declaration, you can give an optional 5th characteristic, the name of the _other_unkeyed local variable in the body of the method. This defaults to "_other_unkeyed" but you can name it something else if you like: Let the _other_unkeyed name default like so:
<method foo _other_unkeyed=opt=wob=ekind.code> _other_unkeyed </>
<foo 3 4/>
<vector 3 4/>

Now give it a more meaningful name like so:
<method foo _other_unkeyed=opt=wob=ekind.code=stash> stash </>
<foo 3 4/>
<vector 3 4/>

If we use the special name of "_add_to_environment", then the values will be added to the object bound to _environment with non-negative integer keys.
<method foo _other_unkeyed=opt=wob=ekind.code=_add_to_environment> 
    _environment.1 </>
<foo 3 4/>
4
_other_unkeyed_f_name behaves similarly for parameters to a class and for _other_keyed parameters as well.

a wob
Parameter keyDefault valueType
_other_keyedopt with ekind of expression
_other_keyed is a special arg that, if a method is defined to take it, collects all the keyed args that are not declared as regular method parameters into one object. To define a method that takes _other_keyed arguments, just make one of its arguments _other_keyed.

<method foo6  _other_keyed=opt>
     _other_keyed.myarg
   </>
<foo6 myarg=32/>
32

You can used _other_keyed in conjunction with other arguments:
<method foo7 a=req b=2 _other_keyed=opt _other_unkeyed=opt>
   <v a b _other_keyed _other_unkeyed/>
</method>
<foo7 111 b=222 333 444 x=555 y=666/>
<vector 111 222 <thing x=555 y=666/> <vector 333 444/>/>

Above we see that 111 is bound to "a" and it is a required arg. If we wnt to pass in 222 for "b", we must pass it in using its key rather than simply by position because _other_unkeyed args are permitted and 222 would go to _other_unkeyed if we didn't pass it in by key. The 333 and 444 are unkeyed and since all of our req args are "used up", they go into a vector of 333444 which is bound to _other_unkeyed. Remaining we have x=555 y=666 in our call. If we had not specified _other_keyed in the parameters of our method definition, our call would error because x and y would be illegal. But because we HAVE specified other_keyed, they are allowed and stuck into an instance of thing with fields x and y containing values of 555 and 666 respecitively. The order of mentioning _other_keyed and _other_unkeyed in the parameters of a method definition doesn't matter.
Usually when you are allowing other_keyed, you, the programmer, don't know what keys some caller of your method is likely to pass. So normally you need to loop through the other keys and do something with them like so:
<method foo8 _other_keyed=opt>
  _other_keyed.<for_each include=string_key combiner=join>
      <join key " has value: " value ". "/>
  </for_each>
</method>
<foo8 color="blue" size="XL"/>
"color has value: blue. size has value: XL. "

Naming the _other_keyed local variable

After the ekind in a parameter declaration, you can give an optional 5th characteristic, the name of the _other_keyed local variable in the body of the method. This defaults to "_other_keyed" but you can name it something else if you like: Let the _other_keyed name default like so:
<method foo _other_keyed=opt> _other_keyed </>
<foo color="blue" size="XL"/>
<thing color="blue" size="XL"/>

Now give it a more meaningful name like so:
<method foo _other_keyed=opt=wob=ekind.code=my_specs> my_specs </>
<foo color="blue" size="XL"/>
<thing color="blue" size="XL"/>

If we use the special name of "_add_to_environment", then the values will be added to the local variables.
<method foo _other_keyed=opt=wob=ekind.code=_add_to_environment> 
    size </>
<foo size="XL"/>
"XL"
You can explicitly get to the object that represents the environment via _environment if you like:
<method foo _other_keyed=opt=wob=ekind.code=_add_to_environment> 
    _environment.size </>
<foo size="XL"/>
"XL"

a wob
Parameter keyDefault valueType
_bodyoptvector
The content area of a call to method is its "body" or "implementation". This is the code that is executed when the method is called. The code is executed with local variables named after the parameters bound to the values of the arguments passed in. If an optional arg is not passed in, the code specified for its default value is executed to get the value of the arg for each call to the method. All methods in Water return a value. There are no "void" methods that do not return a value. An object might be null or the empty string or some other value that may not be used by the caller, but it will be returned none the less.
The value returned is the value of the last expression executed in the body. If there are no tricky control structures like calls to if the last expression will be the last top level expression in the body. You can force the return at any point in the body, however, by calling the method return and passing in its from parameter the name of the method.

<method foo>
         <if> true <return 97 from="foo"/></>
         68
      </method>
<foo/>
97
See documentation in return for more details.

a wob
Parameter keyDefault valueType
_return_typewob with ekind of code
You can declare the return type of a method with a special "parameter" named "_return_type".

<set_type_checking "error"/>
<method foo8 a_num=required=integer _return_type=string> true </>
<foo8 23/>
error
This errors because the method declared that its return type is string but a boolean, true, was returned instead. _return_type is option with the default value being wob meaning the method canreturn anything.

a wob
Parameter keyDefault valueType
_argsfalse
Programs that write code need some special support. Sometimes you have all of the arguments you want to pass to a method bundled up into an object and you want to call the method. Below we have the args that we want to use in the variable my_args. Its value is just <thing a1=19 a2=29/>, an object containing a field for each argument. When we call foo passing in our args in my_thing via the special arg _arg like so: <foo _args=my_args/>, it behaves as if we had said instead: <foo a1=19 a2=29/>

<method foo a1=req a2=opt> <v a1 a2/></>
<set my_args=<thing a1=19 a2=29/>/>
<foo _args=my_args/>
<v 19 29/>

We can also use _args to pass in arguments "by-position." Below we're passing in 19, 29, 30, 49 without using the actual parameter names of a1, a2, a3, a4. This is similar to calling foo like so: <foo 19 29 39 49/>
Example: by_position args passed via _args
<method foo a1=req a2=req a3=opt a4=opt> <v a1 a2 a3 a4/> </>
<foo _args=<vector 19 29 39 49/>/>
<vector 19 29 39 49/>

When we define methods that take _other_unkeyed, we can still use _args in the "by-position" style like so:
Example: by_position args passed via _args
<method foo a1=req a2=req a3=opt a4=opt _other_unkeyed=opt> <v a1 a2 a3 a4 _other_unkeyed/> </>
<foo _args=<vector 19 29 39 49 59 69/>/>
<vector 19 29 opt opt <vector 39 49 59 69/>/>

a wob
Parameter keyDefault valueType
_save_expression_callfalse
Rarely will you need this functionality but it comes in handy if you are writing code that needs to write code or need a flexible syntax.
When you call a method with some keyword args, you cannot normally find out the order that those args were passed to the method. In fact you can't find out a variety of things like whether they were passed as keywords or by position.
By defining the method with a "param" of _save_expression_call=true, it will not be a real param, but will instead bind the expression of the call to the local variable of _expression_call when the body of the method being called is executed.

<method foo x=2 _save_expression_call=true _return_type=true>
  _expression_call
</method>
 <foo x=4/>.<is_a expression.call/>
true

What good is this? You can inspect the result of <foo x=4/> above, but here's some ideas:

Computing the method of a call

Another thing you occasionally want to do is compute the method to be called.
Below is a contrived example but it illustrates the power of this technique. We are computing the name of the method to call with <join "pl" "us"/> to give us the string "plus". Next we use "get" to find the actual method object inside of number via: number.<get <join "pl" "us"/>/> Finally we need to wrap our expression in a "do" call so that execute won't think we're trying to call "number". <do number.<get <join "pl" "us"/>/>/>
Ok now we're ready to show the actual call.
<<do number.<get <join "pl" "us"/>/>/> 3 4/>
7

The above convoluted call is the same as calling <plus 3 4/> but by replacing the active parts of computing the method name with something meaningful in your application, you can programmatically make up calls. The method call is also useful for this purpose, though you can do everything that it does by using _args and the above technique for computing the method.


Execution of a Call

Here's a blow by blow description of what happens during a method call.
Take the call 1.<plus 2/> for example:
1 is the subject.
plus is the method name.
2 is the argument.
1 is executed and results in 1 (numbers are self-evaluating).
"plus" is looked up in 1. 1 has no fields so plus is looked up in the parent of 1, which is integer Integer may not have a plus field so its parent, number is looked up. Number has a plus field so we get its value, the plus method. You can see this by executing 1.plus , which is often useful in debugging. Now that we have the method, we can execute its arguments. plus has only an _other_unkeyed parameter meaning it can have any number of arguments. plus's _other_unkeyed parameter has an ekind of code so 2 is executed and results in 2. Since the value of plus is a method, as opposed to a class or other object, we now call the method. (If plus were not a method, we would make an instance of it. See the doc on class.)
In calling, first local variables are made of each parameter of the method. In this case, plus has only one parameter, but it is "_other_unkeyed" which means it will be bound to a vector of the arguments passed to plus. _other_unkeyed will be bound to <vector 2/> We also bind the local variable _subject to the subject of the call, in this case 1.
With all of our parameters and _subject bound to the values passed in, we now execute the implementation of plus If there are any local variable references, they execute to the values that have been passed in. In this case, _subject will execute to 1 and _other_unkeyed.0 will execute to 2 The last expression executed in the method implementation has its value returned. In this case, the implementation adds the two numbers together and returns three. You can explicitly call return to make an early return, but usually that is not necessary. class is very similar to method in regard to the treatment of its parameters. It has req , opt , _other_unkeyed , keyed arguments, default values, types and execution kinds.