Function or method call

We have already see a function call in an earlier example: the print function. BeanShell has a number of built in functions that may be used, and the Patchworks system has a library of functions that may be used to control simulations and process data set.

Functions may or may not return results depending on how they were defined. For example, the print function does not return a result (as indicated by the keyword void in the function documentation). The getSourceFileInfo command returns a String. The results returned from a function can be assigned to a variable or can be ignored.

filename = getSourceFileInfo();

Method calls apply to objects. They are similar to function calls in that they return values as specified by the return type, or not return a value if the return type is void. If a method returns another object then method calls may be chained together. For example, the following trivial code that replaces characters in a string and then converts it to lower case:

firstName = "John";
temp = firstName.toUpperCase();
temp = temp.replace("O", "o");

could have the two method calls chained together:

temp = firstName.toUpperCase().replace("O", "o");

In this simple example the two String objects were chained together, but any types of objects can be chained. For example, this statement uses the Patchworks API to get the Target associated with the account named “product.Yield.managed.Conif” and then sets the minimum target value to 500000 in period 1.

control.getTarget("product.Yield.managed.Conif").setMinimum(500000, 1);

Method or function call statements are similar to assignment statements.