In this post I will discuss generic methods introduced in 1.9.7 version.
Let's start with two basic things. Any message in the language consist of a verb (predefined action : get, set, insert, add, ...), a signature (user defined) and a number of parameters
For example in the following expression
is used. insert is a verb, index&literal is a signature (consisting of two subjects: index and literal) and 2 is a number of parameters.
Or in this message call
get&length is used
And secondly the message can be created dynamically at run time combining a signature symbol and a generic message (a message without a signature)
These two principles are used in the generic method implementation. A generic method may responds to the message with the same verb and the parameter number but with any signature. Original signature is presaved and can be used inside the method.
Let's consider a simple example. Suppose we have the class containing coordinates
Let's create a variable which can contain a point
And let's define the operations with the point coordinates. We will use generic methods
How it works? Let's consider the simple use case
When append&x message is sent to an instance of PointVariable, a class dispatcher tries to resolve the message directly, if no match was found it will call the generic method - append, a built-in variable contains our original signature - %x.
is similar to
Note that our example will work with a Point class containing arbitrary number of coordinates (one, two, three and so on)
This principle is used in system'dynamic'DynamicStruct class.