| parametric class | categories Objects, Classes and Slots Calls and Slot Access |
Updates |
Calls are the basic building blocks of a CLAIRE program. A call is a polymorphic function call (a message) with the usual syntax : a selector followed by a list of arguments between parentheses. A call is used to invoke a method.
When the selector is an operation, such as +, -, %, etc... (% denotes set membership) an infix syntax is allowed (with explicit precedence rules) :
| eval(x), f(x,y,z), x.price, y.name |
| John.father // may provoke an error if John.father is unknown get(father,john) // may return unknown |
| 1 + 2 1 + 2 * 3 |
| (x = 1) & ((y = 2) | (y > 2)) & (z = 3) |
A dynamic functional call where the selector is evaluated can be obtained using the call method. For instance, call(+,1,2) is equivalent to +(1,2) and call(show,x) is equivalent to show(x). The difference is that the first parameter to call can be any expression. This is the key for writing parametric methods using the inline capabilities of CLAIRE. This also means that using call is not a safe way to force dynamic binding, this should be done using the property abstract. An abstract property is a property that can be re-defined at any time and, therefore, relies on dynamic binding. Notice that call takes a variable number of arguments. A similar method named apply can be used to apply a property to an explicit list of arguments.
Since the use of call is somehow tedious, CLAIRE supports the use of variables (local or global) as selectors in a function call and re-introduce the call implicitly. For instance :
| compose(f:property, g:property, x:any) : any => f(g(x)) |
| compose(f:property, g:property, x:any) => call(f, call(g,x)) |
| categories | Calls and Slot Access | normal dispatch | Core method |
apply(m,lx) applies the method m to the argument list lx. For instance the following expressions are equivalent :
| apply(+ @ integer, list(1, 3)) -> 4 1 + 3 -> 4 |
| categories | Calls and Slot Access | normal dispatch | Core method |
apply(self,%l) applies the lambda expression self to the argument list %l.
| categories | Calls and Slot Access | normal dispatch | Core method |
apply(p,l) is equivalent to a function call where the selector is p and the argument list is l. For instance the following expressions are equivalent :
| apply(+, list(1,2)) -> 3 1 + 2 -> 3 call(+, 1, 2) -> 3 |
| categories | Calls and Slot Access | normal dispatch | Core method |
apply(self,ls,l) applies the function self to the argument list l, where ls is the list of sort of the arguments and the result (i.e. length(ls) = length(l) + 1). For instance, if self is the external function that defines + @ integer :
| apply(f, list(integer,integer,integer), list(1,2)) -> 1 + 2 |
| categories | Calls and Slot Access | normal dispatch | Core method |
call(p, x1, x2, ..., xn) is equivalent to apply(p, list(x1 ,x2 , ... , xn)).
| categories | Calls and Slot Access | normal dispatch | Kernel method |
funcall(m,x) applies a method with one argument
| categories | Calls and Slot Access | normal dispatch | Kernel method |
funcall(l,x) applies a lambda with one argument
| categories | Calls and Slot Access | normal dispatch | Kernel method |
funcall(m,x,y) applies a method with two argument
| categories | Calls and Slot Access | normal dispatch | Kernel method |
funcall(l,x,y) applies a lambda with two argument
| categories | Calls and Slot Access | normal dispatch | Kernel method |
funcall provides an easy interface with external (C++) functions. funcall(f, s1, x, s) applies an external function to an argument of sort s1. The sort of the returned value must be passed as an argument. Notice that the last argument is the sort of the result, and that giving an erroneous sort argument will likely produce a fatal error.
| categories | Calls and Slot Access | normal dispatch | Kernel method |
funcall(m,x,y) applies a method with three argument
| categories | Calls and Slot Access | normal dispatch | Kernel method |
funcall(l,x,y) applies a lambda with three argument
| categories | Calls and Slot Access | normal dispatch | Kernel method |
like funcall(f, s1, x, s) but for external functions with two arguments.
| categories | Calls and Slot Access | normal dispatch | Kernel method |
like funcall(f, s1, x, s) but for external functions with three arguments.