| Methods and Types Iterations |
categories Tables, Rules and Hypothetical Reasoning Tables |
Rules |
Named arrays, called tables, can be defined in CLAIRE with the following syntax :
| <name>[var:<domain>] : <type> := <expression(var)> |
| square[x:(0 .. 20)] : integer := (x * x) creator[x:class] : string := "who created that class" maximum[x:set[0 .. 10]] : integer := (if x min(x,> @ integer) else 0) |
| square[1], square[2] := 4, square[4] :+ 5 |
| distance[x:tuple(city,city)] : integer := 0 cost[x:tuple(1 .. 10, 1 .. 10)] : integer := 0 |
| cost[x:(1 .. 10), y:(1 .. 10)] : integer := 0 |
| let square := make_table((1 .. 10), integer, 0) in (for n in (1 .. 10)) square[n] := n * n, ...) |
| categories | Tables | normal dispatch | Core method |
erase(a) removes all value pairs contained in the table. This means that, on one hand, the value a[x] becomes unknown for each object x, and also that any references to an object from the table's domain or an associated value is lost, which may be useful to allow for complete garbage collection.
| categories | Tables | normal dispatch | Kernel method |
returns a table with a domain of type d and a range t. The parameter x is the default value, thus x must belong to t, as well as any future value that will be put in the table.
[XL] In XL CLAIRE, tables created by make_table are seen as ephemeral, thus collectable by the GC.
| categories | Tables | normal dispatch | Kernel method |
nth(t,x) returns the element of t that as the key x. nth(t,x) is equivalent to t[x].
| categories | Tables | normal dispatch | Kernel method |
nth(t,x) returns the element of t that as the key tuple(x, y). nth(t,x) is equivalent to t[x,y], t[tuple(x,y)] and nth(t,tuple(x,y)).
| categories | Tables | normal dispatch | Kernel method |
nth=(t,x,y) sets the item of t with key x to y. nth=(t,x,y) is equivalent to t[x] := y.
| categories | Tables | normal dispatch | Kernel method |
nth=(t,x1,x2,y) sets the item t with key tuple(x1,x2) to y nth=(t,x1,x2,y) is equivalent to t[x1,x2] := y.
| categories | Tables | normal dispatch | Kernel method |
put(t,x,y) is equivalent to t[x] := y but does not trigger the rules associated to a. Besides, this operation is performed without any type-checking.