Methods defined on an object can be executed with the method-call expression, which has the following syntax:
receiver.method(arg1, arg2, ...)
In this example receiver is the object where method may be called, and arg1, arg2 are expressions. There are is no limit to the number of arguments sent, although even if there are no arguments the parenthesis must exist. Arguments are evaluated from left to right.
The receiver may be omitted, in which case it is assumed to be the current object. If receiver does not exist in the database, the error ~objnf is thrown.
Any ColdC Data (with the exception of Frobs) may be used in place of the object as the receiver. If a method is called in this manner, the interpreter will lookup an object with an object name that is the same as the type of data being used (such as an object named $string if the data is a 'string). If an object is found in the database with this name, the method is called on that object and the data is sent as the first argument (subsequent arguments will still be sent). If not, the error ~objnf is thrown.
If a Frob is used in place of receiver, the class object for the frob becomes the receiver and the representation of the frob is sent as the first argument. Because of this difference it is possible to have a special method that only a frob may call. For more information on frobbed methods see Defining Methods.
method must be either the name of the method, or an expression which results in a symbol for the name of the method. If method cannot be found on receiver or any of receiver's ancestors, then the error ~methodnf is thrown.
The result from a method-call expression is the value returned by the method. If the method does not return a value, the result is receiver. If receiver is a frob, then the method is called on the frob's class object, with the frob's representation inserted as the first argument (other arguments are placed after the representation).
Here are some examples of method-call expressions:
.tell("I don't see that here.");
=> [$lynx, $dancer, $jenner]
([1, 2, 3]).reverse()
=> [3, 2, 1]
$parser.(tosym(what + "_mesg"))(messages)
(<$thing_frob, #[['myname, "coins"], ['amount, 300]]>).name()
=> "300 coins"
In order to prevent incidents of infinite recursion, there is a maximum calling depth for methods. If calling a method would exceed the maximum calling depth, the error ~maxdepth is thrown.
If a method is overridden it is still possible for it to be called. For more information see the section Calling Overridden Methods.
Data | Operators | Variable Expression | Function Call Expression | Method Call Expression | Error Handling Expression | Looping Expressions