Methods
^ Kernel method
x:integer ^ y:integer -> integer
x:float ^ y:float -> float
x:list ^ y:integer -> list
x:set ^ y:set -> set
(x ^ y) returns x ^ y when x and y are numbers. If x is an integer, then y must be a positive integer, otherwise an error is raised.
(l ^ y) skips the y first members of the list l. If the integer y is bigger than the length of the list l, the result is the empty list, otherwise it is the sublist starting at the y+1 position in l (up to the end).
(s1 ^ s2) returns the intersection of the two sets s1 and s2 that is the set of entities that belong to both s1 and s2.
Other internal restrictions of the property ^ exist, where ^ denotes the intersection (it is used for the type lattice)
^2 Core method
^2(x:integer) -> integer
^2(x) returns 2 to the power of x
% Kernel method
x:any % y:class -> boolean
x:any % y:collection -> boolean
(x % y) returns (x "belongs to" y) for any entity x and any abstract set y. An abstract set is an object that represents a set, which is a type or a list.
* Kernel method
x:integer * y:integer -> integer
x:float * y:float -> float
(x * y) returns x ´ y when x and y are numbers. If x is an integer, then y must also be an integer, otherwise an error is raised (explicit conversion is supported with float!).
The operation * defines a commutative monoid, with associated divisibility operator divide? and associated division /.
/ Kernel method
x:integer / y:integer -> integer
x:float / y:float -> float
(x / y) returns x / y when x and y are numbers. If x is an integer, then y must also be an integer, otherwise an error is raised (explicit conversion is supported with float!).
- Kernel method
x:integer - y:integer -> integer
x:float - y:float -> float
-(x:integer) -> integer
-(x:float) -> float
(x - y) returns x + y when x and y are numbers. -(x) returns the opposite of x.
/+.; Kernel method
x:list /+ y:list -> list
x:string /+ y:string -> string
x:symbol /+ y:(string U symbol) -> symbol
(x /+ y) returns the concatenation of x and y ( represents the append operation). Concatenation is an associative operation that applies to strings, lists and symbols. It is not represented with + because it is not commutative. When two symbols are concatenated, the resulting symbol belongs to the namespace (module) of the first symbol, thus the second symbol is simply used as a string. By extension, a symbol can be concatenated directly with a string.
.. , - ..;- Kernel method
.. x:integer .. y:integer -> Type
-- x:integer .. y:integer -> Interval
(x .. y) returns the interval {z | x £ z £ y}. Intervals are only supported for integers, in CLAIRE v3.0. Notice that (3 .. 1) returns the empty set, which is a type. The new method (x – y) is an explicit interval constructor (it produces an error if the first argument is larger than the second).The result is an object from the class Interval, which is a type.
=, != Kernel method
x:any = y:any -> boolean
x:any != y:any -> boolean
(x = y) returns true if x is equal to y and nil otherwise. Equality is defined in Section 2: equality is defined as identity for all entities except strings, lists and sets. For lists, sets and strings, equality is defined recursively as follows: x and y are equal if they are of same size n and if x[i] is equal to y[i] for all i in (1 .. n).
(x != y) is simply the negation of (x = y).
=type? Core method
=type?(x:any, y:any) -> boolean
returns true if x and y denote the same type. For example =type?(boolean, {true, false}) returns true because final(boolean) was declared after the two instances true and false were created, so the system knows that no other instances of boolean may ever be created in the future. This equality is stronger than set equality in the sense that the system answers true if it knows that the set equality will hold ever after.
<=, >=, <, > Kernel method
x:integer <= y:integer -> boolean
x:float <= y:float -> boolean
x:char <= y:char -> boolean
x:string <= y:string -> boolean
x:type <= y:type -> boolean
x:X < y:X -> boolean for X = integer, float, char and string
x:X > y:X -> boolean for X = integer, float, char and string
x:X >= y:X -> boolean for X = integer, float, char and string
The basic order property is <=. It is defined on integers and floats with the obvious meaning. On characters, it is the ASCII order, and on strings it is the lexicographic order induced by the ASCII order on characters. The order on types is the inclusion: ((x <= y) if all members of type x are necessarily members of type y).
(x < y), (x > y) and (x >= y) are only defined for numbers, char and strings with the usual meaning.
<< , >> , Kernel method
l:list << n:integer -> list
x:integer << n:integer -> integer
x:integer >> n:integer -> integer
l:string << n:integer -> string
(l << n) left-shifts the list l by n units, which means that the n first members of the list are removed. This is a method with a side-effect since the returned value is the original list, which has been modified. (x <<n) and (x >> n) are the result of shifting the integer x seen as a bitvector respectively to the left and to the right by n positions.
(s << n) removes the n first characters of a string s. This is an efficient but destructive operation (no allocation, but the initial string is lost).
@ Core method
p:property @ t:type -> entity
p:property @ l:list[type] -> entity
t:type @ p:parameter -> type
(p @ t) returns the restriction of p that applies to arguments of type t. When no restrictions applies, the value nil is returned. If more than one restriction applies, the value unknown is returned. Notice that the form p@t (without blank spaces) is used to print the restriction and also in the control structure <property>@<class>(...).
(p @ list(t1,..tn)) is similar and returns the restriction of p that applies to arguments in t1 X … X tn.
(t @ p) returns the type that is inferred for x.p when x is an object of type t and p a parameter (read-only property).
abs Core method
abs(x:integer) -> integer
abs (x:float) -> float
abs(x) returns the absolute value (-(x) is x is negative, x otherwise).
abstract Core method
abstract(c:class) -> void
abstract(p:property) -> void
abstract(c) forbids the class c to have any instance. abstract(p) defines p as an extensible property. This is used by the compiler to preserve the ability to add new restrictions to p in the future that would change its semantics on existing classes. By default, a property is extensible until it is compiled. A corollary is that function calls that use extensible properties are compiled using late binding.
active? Compile slot
compiler.active? -> boolean
This boolean is set to true when the compiler is active (i.e., compiling CLAIRE code into C++ code). This is useful to introduce variants between the compiled and interpreted code (such as different sizes). Note that there is another flag, loading?, to see if a file is loaded by the compiler.
add Kernel method
add(s:set,x:any) -> set
add(l:list,x:any) -> list
add(p:relation,x:object,y:any) -> any
add(s,x) adds x to the set s. The returned value is the set s È {x}. This method may modify the set s but not necessarily. When x is a list, add(l,x) inserts x at the end of l. The returned value is also the list obtained by appending (x) to l, and l may be modified as a result but not necessarily. The pseudo-destructive behavior of add is similar to that of add*, which is described below.
add(p,x,y) is equivalent to p(x) :add y (This form is interesting when one wants to write such an expression for a variable p)
add* Kernel method
add*(l1:list, l2:list) -> list
add*(l1,l2) returns the concatenated list l1 . l2, but it is destructive: it uses l1 as the data structure on which to perform the concatenation. Hence, the original l1 is no longer available after the method add* has been called.
and Kernel method
and(x :integer,y :integer) -> integer
and(x,y) returns the bitwise intersection of two integers (seen as bitvectors).
apply Core method
apply(p:property, l:list) -> any
apply(f:external_function, ls:list[class], lx:list) -> any
apply(la:lambda, lx:list) -> any
apply(m:method, lx:list) -> any
apply(p,l) is equivalent to a function call where the selector is p and the argument list is l. For instance, apply(+,list(1,2)) = (1 + 2) = call(+,1,2).
apply(f,ls,l) applies the function f 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 f is the external function that defines + @ integer, apply(f,list(integer,integer,integer),list(1,2)) = 1 + 2.
apply(la,lx) applies the lambda expression to the argument list. apply(m,lx) applies the method to the argument list.
array! Kernel method
array!(x:list,t:type) -> type[t[]]
creates a copy of the list x that is represented as an array. The member type must be given as a parameter t and an error will occur if a member of the list does not belong to t.
arg1 / arg2 Kernel slot
arg1(x:Interval) -> any
arg2(x:Interval) -> any
These slots contain respectively the minimal and maximal element of a CLAIRE interval.
begin Kernel method
begin(m:module) -> void
sets the current namespace to m (a module).
but Core method
but(s:any,x:any) -> any
Returns the set of members of s that are different from x.
car, cdr Kernel method
car(l:list) ® type[member(l)]
cdr(l:list) ® type[l]
These two classical LISP methods return the head of the list , e.g. l[1] (for car) and its tail, e.g. the list l starting at its second element (for cdr).
call Kernel method
call(p:property, l:listargs) ® any
call(x:lambda, l:listargs) ® any
call(X,x1,x2 ,...,xn) is equivalent to apply(X,list(x1,x2 ,...,xn)).
cast! Kernel method
cast!(s:bag,t:type) -> bag
cast(s,t) sets the member type of the bag s to t. This is a system method, that should not be used lightly since it does not perform any check and may yield nasty errors. The proper way to cast a bag is to use “as”: (s as t).
char! Kernel method
char!(n:integer) -> char
char!(n) returns the character which ASCII code is n.
class! Core method
class!(x:any) -> class
class!(x) returns the intersection of all classes y such that x <= y (Such an intersection always exists since classes are organized in a lattice). Hence, if c is a class class!(c)=c.
close Core method
close(m:module) -> module
close(c:class) -> class
close(e:exception) -> any
close(v:global_variable) -> global_variable
The method close is called each time an object is created. It is executed and returns the created object. It can sometimes be very helpful to define new restrictions, they will be automatically called when an instance is created. Exceptions are a special case: raising an exception is done internally by creating an instance of exception. The method close is responsible for looking for the innermost handler, etc.
cons Kernel method
cons(x:any, l:list) -> list
This traditional method appends x at the beginning of l and returns the constructed list.
contradiction!() Kernel method
contradiction!() -> void
This method creates a contradiction, which is an instance of the class contradiction..; It is equivalent to contradiction() but is more efficient and should be preferred.
copy Kernel method
copy(x:object) -> object
copy(s:bag) -> bag copy(a:array) -> array
copy(s:string) -> string
copy(x) returns a duplicate of the object x. It is not recursive : the slots of the copied object are shared with that of the original one. Similarly, the copy of a bag (a set or a list) returns a fresh set or list with the same elements and the copy of a string is ... a copy of the string.
cos Kernel method
cos(x:float) -> float
cos(x) returns the cosine of x (x is expressed in radians).
date! Kernel method
date!(i:integer) -> string
date!(i) returns the date, using the integer parameter i to indicate whether the full date is needed or only the day or the time. For instance
date!(0) = "Thu Mar 9 08:04:22 2000”
date!(1) = "Thu Mar 9 2000”
date!(2) = "08:04:22”
delete Kernel method
delete(p:relation, x:object, y:any) -> any
delete(s:bag, x:any) -> bag
delete(s,x) returns s if x is not in s and the list (resp. set) s without the first (resp. only) occurrence of x otherwise. delete(p,x,y) is equivalent to p(x) :delete y. This is a destructive method in the sense that it modifies its input argument. The proper way to use delete, therefore, is either destructive (l :delete x) or non-destructive (delete(copy(l),x)).
descendents Core slot
descendents(x:class) -> set[class]
For a class c, c.descendents is the set all classes that are under c in the hierarchy (transitive closure of the subclass relation).
difference Kernel method
difference(s:set, t:set) -> set
difference(s,t) returns the difference set s - t, that is the set of all elements of s which are not elements of t.
domain Core slot
domain(r:restriction) ® list
domain(r:relation) ® any
A restriction is either a slot or a method. If r is a slot, domain(r) is the class on which r is defined. If r is a method, r.domain is the list formed by the types of the parameters required by the method. For a relation r, r.domain is the type on which r is defined.
end_of_string Kernel method
end_of_string() ® string
end_of_string() returns the string containing everything that has been printed since the last call to print_in_string().
erase Kernel method
erase(a:table) ® any
erase(r:property,x:any) ® any
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.
erase(p,x) removes the value associated to x with the property p. The default value, or the unknown value, is placed in the slot x.p, and the inverse if updated (if any).
exception! Kernel method
exception!() ® exception
exception!() returns the last exception that was raised.
exit Kernel method
exit(n:integer) ® void
exit(n) stops claire running and returns to the hosting system the value n. What can happen next is platform-dependent
factor? Kernel method
factor?(x:integer, y:integer) -> boolean
factor?(x,y) returns true if x is a multiple of y.
fcall Core method
fcall(f:external_function, s1:class, x:any, s:class) -> any
fcall(f:external_function, s1:class, x:any, s2:class, y:any, s:class) -> any
fcall(f:external_function, s1:class, x:any, s2:class, y:any,
s3:class,z :class,s :class) -> any
fcall provide an easy interface with external (C++) functions. fcall(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 (cf. Appendix C). . fcall(f,s1,x,s2,y,s) is the equivalent method in the two-arguments case.
final Core method
final (c:class) -> void
final (p:property) -> void
final(c) forbids the user to create any subclass of the class c. If c is a constant class, this is taken as a “diet” compiling directive.
final(p) change the extensibility status of the property p (represented with the slot open) so that the property p becomes closed, which means that a new restriction may no longer be added if it causes an inheritance conflict.
finite? Core method
finite?(t:type) -> boolean
finite?(t) returns true if the type t represents a finite set. Set iteration (with the for loop) can only be done over finite sets.
float! Kernel method
float!(x:integer) -> float
float!(x:string) -> float
transforms an integer or a string into a float.
flush Kernel method
flush(p:port) -> void
Communications with ports are buffered, so it can happen that some messages wait in a queue for others to come, before being actually sent to their destination port. flush(p) for input and output ports and empties the buffer associated with p, by physically sending the print messages to their destination.
fopen, fclose Kernel method
fopen(s1:string,s2:string) -> port
fclose(p:port) -> any
fopen returns a port that is handle on the file or external device associated with it. The first string argument is the name of the file, the second is a combination of several control characters, among which 'r' allows reading the file, 'w' (over)writing the file and 'a' appending what will be write at the end of the file. Other possibilities may be offered, depending on the underlying possibilities. Such other possibilities are platform-dependent.
format Kernel method
format(string,list) -> any
This method does the same thing as printf, except that there are always two arguments, thus the arguments must be replaced by an explicit list.
formula Core slot
formula(m:method) -> lambda Core
formula(d:demon) -> lambda Core
formula gives the formula associated with the method/demon.
funcall Core slot
funcall(m:method, x:any) -> any
funcall(m:method, x:any, y:any) -> any
funcall(m:method, x:any, y:any, z:any) -> any
funcall(f:function, x:any, cx:class, crange:class) -> any
funcall(f:function, x:any, cx:class, y:any, cy:class, crange:class) -> any
funcall(f:function, x:any, y:any, cy:class, z:any, cz:class, crange:class) -> any
funcall provide 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 (cf. Appendix C). funcall(f,s1,x,s2,y,s) is the equivalent method in the two-arguments case, and funcall(f,s1,x,s2,y,s3,y, s) is the equivalent method in the three-arguments case. Notice that the LAST argument is the sort of the result, and that giving an erroneous sort argument will likely produce a fatal error.
funcall also applies a method or a lambda to one or two arguments.
Last, funcall may be applied directly to a function, that is a primitive entity that represents a C++ function. This method is provided for expert users, since it is a system method that requires the type of each arguments (cx,cy, …) and the type of the return value (crange), which must be provided as classes. Failure to provide the proper sort (i.e., this type information that is usually found in the srange slot of the method) will provoke a system failure.
gensym Kernel method
gensym() -> symbol
gensym(s:string) -> symbol
gensym() generates randomly a new symbol. gensym(s) generates randomly a new symbol that begin with s.
get Kernel method
get(p:property + slot, x:object) -> any Core
get(a:table, x:any) -> integer Core
get(s:string, c:char) -> integer Core
get(l:list, x:any) -> integer Core
get(m:module) -> integer Core
get(p,x) is equivalent to p(x), but without any verification on unknown. So does get(a,x) for a table.get(s,x) returns i such that s[i]=x (if no such i exists, 0 is returned). So does get(l,x) for a list. get(m) is equivalent for a module m to (load(m), open(m))
get_module Core, Optimize method
get_module(s:symbol) -> module Core
get_module(x:thing) -> module Optimize
get_module returns the module where the identifier s was created.
get_value Kernel method
get_value(s:string) -> any
get_value(m:module, s:string) -> any
returns the object whose name corresponds to the string; if a module argument is passed, the associated symbol is sought in the module’s namespace, otherwise the module claire is used by default. To find the value associated to a string within the current module, simply use get_value(module!(),s).
getc Kernel method
getc(p:port) -> char
getc(p) returns the next character read on port p.
getenv Kernel method
getenv(s:string) -> string
getenv(s) returns the value of the environment variable s if it exists (an error occurs otherwise since an attempt is made to create a string from the NULL value that is returned by the environment).
hash Kernel method
hash(l:list,x:any) -> integer
hash(n:integer,x:any) -> integer
hash(l,x) returns an integer between 1 and length(l) that is obtained through generic hashing. To obtain the best dispersion, one may use a list of size 2i-3. This function can be used to implement hash tables in CLAIRE; it used to be the basis of the table implementation before version 4.
Id Kernel method
Id(x:any) -> type[x]
Id(x) returns x. Id has a special behavior when compiled which makes it useful. The argument is evaluated before being compiled. The intended use is with global variables: the compiler uses the actual value of the variable instead of a reference to the global variable. This is very convenient to introduce parameters that are defined outside the module that is being compiled.
This is also used to tell the compiler that an iteration should make explicit use of all iterations rules that may apply to some subclasses of the set expression that is being iterated.
inherit? Core method
inherit?(c1:class, c2:class) -> boolean
inherit?(c1,c2) returns (c2 % ancestors(c1))
instances Kernel slot
instances(c:class) ® type[set[c]]
returns the set of all instances of c, created up to now (if c has not been declared ephemeral).
instanced Core method
instanced(c:class) ® void
instanced(c) tells CLAIRE to maintain the list of instances (e.g, c.instances). This is not necessary if c inherits from things, but otherwise, CLAIRE will assume by default that the extension is not kept. This choice has a strong impact:
· if the extension is kept, the class may be used as a set but objects will not be garbage collected (explicit kill is necessary)
· otherwise, the class cannot be enumerated (like in “for c in class show(c)”) but garbage collection is implicit (memory is reclaimed as soon as the object is no longer used).
integer! Kernel method
integer!(s:string) -> integer
integer!(f:float) -> integer
integer!(c:char) -> integer
integer!(l:set[(0 .. 63)]) -> integer
integer!(s:symbol) -> integer
integer!(s) returns the integer denoted by the string s if s is a string formed by a sign and a succession of digits, integer!(f) returns the lower integer approximation of f, integer!(c) returns the ASCII code of c and integer!(l) returns the integer represented by the bitvector l, i.e. the sum of all 2i for i in l. Last, integer(s) returns a unique index associated to a symbol s.
inverse Kernel slot
inverse(r:relation) -> relation
r.inverse contains the inverse relation of r. If the range of r inherits from bag then r is considered multi-valued by default (cf. Section 4.5). If r and its inverse are mono-valued then if r(x) = y then inverse(r)(y) = x. If they are multi-valued, then inverse(r)(y) returns the set (resp. list) of all x such that (y % r(x))
invert Core method
invert(r:relation,x:any) -> any
invert(r,x) return r-1(x) assuming that r has an inverse.
isa Core slot
isa(x:object) -> class
returns the class of which x is an instance.
kill, kill! Kernel method
kill(x:object) -> any Kernel
kill(x:class) -> any Kernel
kill!(x:any) -> any Kernel
kill is used to remove an object from the database of the language. kill does it properly, removing the object from all the relation network but without deallocating. kill! is more brutal and deallocates without any checking.
known? Kernel method
known?(p:relation, x:object) -> boolean
known?(x:any) -> boolean
known?(p,x) is equivalent to get(p,x) != unknown . The general method known? simply returns true whenever the object exists in the database.
last Kernel method
last(l:list) -> type[member(l)]
last(l) returns l[length(l)]
length Kernel method
length(l:bag) -> integer
length(a:array) -> integer
length(l:string) -> integer
returns the length of an array, a bag or a string. The length of a list is not its size ! The following is true:
length(set!(l)) = size(l) = size(set!(l)).
list! Kernel method
list!(a:array) -> type[member_type(a)[]]
list!(s:set) -> type[list[member(s)]]
For any array or set x, list!(s) transforms x into a list. If x is a set, the order of the elements in the list can be anything.
load, sload, oload, eload Reader method
load(s:string) -> any
sload(s:string) -> any
oload(s:string) -> any
eload(s:string) ->any
load(m:module) -> any
sload(m:module) -> any
oload(m:module) -> any
These methods load a file (or the files associated to a module). The difference between them is that load(s) reads and evaluates all the instructions found in the file named s, whereas sload(s) reads, prints, evaluates and prints the results of the evaluation of all the instructions found in the file named s. oload(s) is similar to load(s) but also optimizes the methods that are newly defined by substituting an optimized version of the lambda abstraction. eload(s) is similar to load(s) but assumes that the file only contains expressions (such as f(1,2)). This is convenient for loading data input files using a functional format.
loading? Compile slot
compiler.loading? -> boolean
This boolean is set to true when the compiler is loading a file before compiling it. This is useful to introduce variants between the compiled and interpreted code (see also the active? flag)
log Kernel method
log(x:float) -> float
computes log(x) – base e.
made_of Kernel slot
made_of(m:module) -> list[string]
m.made_of contains the list of files that contain the code of the module.
make_array Kernel method
make_array(n:integer,t:type,x:any) -> type[t[]]
returns an array of length n filled with x. The parameter t is the member_type of the array, thus x must belong to t, as well as any future value that will be put in the array. Note that x is shared for all members of the array, which cause a problem if updates can be performed.
make_list Kernel method
make_list(n:integer,x:any) -> type[list[x]]
returns a list of length n filled with x (e.g., make_list(3,0) = list<any>(0,0,0)). This is a typed list with member type any, thus it can be updated.
make_string Kernel method
make_string(i:integer, c:char) -> string
make_string(s:symbol) -> string
make_string(l:list) -> string
make_string(i,c) returns a string of length i filled with the character c.
make_string(s) returns a string denoting the same identifier. If s is given in the qualified form (module/identifer), than the result will contain the name of the module ("module/identifier").
make_string(l) creates a string from the list of its characters.
member Core method
member(x:type) -> type
member(x) returns the type of all instances of type x, assuming that x is a claire type which contains objects y such that other objects z can belong to. If this is the case, member(x) is a valid type for all such z, otherwise the returned value is the empty set. For instance, if x is list[integer], all instances of x are lists that contain integers, and all members of these lists are integers. Therefore, member(list[integer]) is integer.
member_type Kernel method
member_type(x:array) -> type
member_type(x) returns the type of all members of the array x. Therefore, member(a) = member_type(a) for an array a.
methods Reader method
methods(d:class,r:class) -> set[method]
methods(d,r) returns the set of methods with a range included in r and a domain which is a tuple which first component is included in d.
min / max Core method
min(m:method[domain:tuple(X,X), range:boolean],
l:set[X] U list[X]) -> type[X]
min(x:integer,y:integer) -> integer
max(x:integer,y:integer) -> integer
given an order function (m(x,y) returns true if x <= y) and a bag, this function returns the minimum of the bag, according to this order. min/max on integer returns the smallest/largest of two integers.
mod Kernel method
mod(x:integer, y:integer) -> integer
mod(x,y) is the rest of the Euclidean division of x by y.
module! Core, Optimize method
module!() -> module
module!(r:restriction) -> module
module!(r) returns the module where the method r was created.
module!() (= system.module! ) returns the current module, that is the module into which the reader is currently reading.
new Core method
new(c:class) -> any
new(c:class, s:symbol) -> thing
new is the generic instantiation method. new(c) creates an object of class c (It is equivalent to c()). new(c,s) creates an object of class c with name s.
not Kernel method
not(x:any) -> boolean
not(x) returns false for all x except false, the empty set and the empty list.
nth, nth=, nth+, nth- Kernel method
nth(a:table, x:any) -> any Kernel
nth(x:integer, i:integer) -> boolean Kernel
nth(l:bag, i:integer) -> any Kernel
nth(a:array, i:integer) -> any Kernel
nth(s:string, i:integer) -> char Kernel
nth=(a:table, x:any, y:any) -> any Kernel
nth=(a:array, x:any, y:any) -> any Kernel
nth=(l:list, i:integer, x:any) -> any Kernel
nth=(s:string, i:integer, x:char) -> char Kernel
nth+(l:list, i:integer, x:any) -> bag Kernel
nth-(l:list, i:integer) -> bag Kernel
nth_put(l:string, i:integer, x:char) -> string Kernel
nth_get(l:string, i:integer) -> string Kernel
nth is used for accessing elements of structured data: nth(l,i) is the ith element of the bag l, nth(s,i) is the ith character of the string s. For tables, nth(a,x) is equivalent to a[x], even when x is not an integer. Finally, nth also deals with the bitvector representation of integers: nth(x,i) returns true if the ith digit of x in base 2 is 1.
nth= is used for changing an element at a certain place to a certain value. In all the restrictions nth=(s,i,x) means: change the ith value of s to x.
There exists two other ways of modifying the values in such data structures: nth+ and nth-. nth+ uses the same syntax as nth= : nth+(l,i,x) returns a list (that may be l) where x has been inserted in the ith position. By extension, i may be length(l) + 1, in which case x is inserted at the end of l.
nth- is used for removing an element. nth-(s,i) returns a value that differs from s only in that the ith place has been erased.
Strings in CLAIRE can be used as buffers (arrays of characters) using the methods nth_get and nth_put that do not perform bound checking. The string does not need to be terminated by a null character and any position may be accessed. This use of strings may provoke severe errors since there are no bound checks, thus it should be used scarcely and with a lot of care.
occurrence Language method
occurrence(exp:any, x:variable) -> integer
returns the number of times when the variable x appears in exp.
open Core slot
open(c:class) -> integer
open(r:relation) -> integer
x.open is a slot that tells the extensibility level of the class or relation x.
For a class, there are 6 values: -1 (system.close) means that the class cannot be extended neither with instances nor subclasses; 0 (abstract) means that the class cannot have any instances; 1 (final) means that no new subclasses could be created; 2 (default) is the default status, 3 (system.open) means that the class is explicitly casted as extensible; 4 (ephemeral) says that the class is a subset of ephemeral_object (the list of instances is not maintained). Section 2.2 shows how to define the open status of a class using the proper declarations.
For a relation: open = 1 means that some of the restrictions have been compiled, hence no conflicting new restriction definition is allowed (cf. section 4.1 : extensibility status = closed); open = 2 means undefined; open = 3 means that the extensibility status is “open”, that new restriction may be defined or re-defined at any time.
or Kernel method
or(x:integer,y:integer) -> integer
or(x,y) returns the bitwise union of two integers (seen as bitvectors).
owner Kernel method
owner(x:any) -> class
owner(x) returns the class from which the object is an instance. It x is an object, then owner(x) = isa(x) = the unique class c such that x % instances(c).
parts, part_of, Kernel slot
parts(m:module) -> list
part_of(m:module) -> module
m.part_of contains the module to which m belongs. parts is the inverse of part_of : parts(m) is the set of submodules of m (in the module hierarchy).
port! Kernel method
port!() -> port
port!(s:string) -> port
creates a port that is bound to a string. The first method creates an empty string port that is used for writing. The value of the string associated with the port may be retrieved with the method string!(p:port). The second method transforms an existing string into a port that can be read. This is useful to read an expression stored in a string, although the simpler method read(s:string) is most often enough for the task.
pretty_print Language method
pretty_print(x:any) -> void
performs the pretty_printing of x. For example, you can pretty print claire code: if <inst> is a claire instruction pretty_print(`<inst>) will print it nicely indented (the backquote here is to prevent the instruction from begin evaluated).
princ, print Kernel method
princ(x:integer) -> void
princ(x:string) -> void
princ(x:char) -> void
princ(x:symbol) -> void
princ(x:bag) -> void
print(x:any) -> void
print(x) prints the entity x (x can be anything). princ(x:integer) is equivalent to print(x). If x is a string / char / symbol/ bag, print(x) prints x without the “ / ‘ / ‘/ separator.
print_in_string Kernel method
print_in_string() -> void
print-in-string() opens a new output port that will be stored as a string. The user is given access to the string at the end of the transcription, when the call to end_of_string() returns this string.
put Kernel method
put(p:property, x:object, y:any) -> any
put(a:table, x:object, y:any) -> any
put(s:slot, x:object, y:any) -> any
put(s:symbol,x:any) -> any
put(p,x,y) is equivalent to p(x) := y but does not trigger the rules associated to r or the inverse of r. Besides, this operation is performed without any type-checking. The method put is often used in conjunction with propagate. put(s,x) binds the symbol s to the object x.
put_store Kernel method
put_store(r1: relation, x:any, v:any,b:boolean) -> void
put_store(r,x,v,b) is equivalent to put(r,x,v) but also stores this update in the current world if b is true. The difference with the use of the statement store(p) is that put_store allows the user to control precisely which update should be backtracked. Put_store(r,x,y,b) does nothing if r(x) = y.
putc Kernel method
putc(c:char, p:port) -> void
putc(c,p) sends c to the output port p.
random, random! Kernel method
random(n:integer) -> integer
random (n:integer,m:integer) -> integer
random (b:boolean) -> boolean
random (l:bag) -> any
random!(n:integer) -> void
random(n) returns an integer in (0 .. n-1), supposedly with uniform probability. random(n,m) returns an integer between n and m. random(b:Boolean) returns a random boolean (true or false) is b is true, and false otherwise.
random(l:bag)returns a random member of the bag l. random!(n) resets the seed for the random number generation process.
range Kernel, Language method
range(r:restriction) -> any Kernel
range(r:relation) -> any Kernel
range(v:global_variable) -> any Kernel
range(v:Variable) -> any Language
For a relation or a restriction r, range(r) returns the allowed type for the values taken by r over its domain. For a variable v, range(v) is the allowed type for the value of v.
read Kernel, Reader method
read(p:property, x:object) -> any Kernel
read(p:port) -> any Reader
read(s:string) -> any Reader
read(p,x) is strictly equivalent to p(x): it reads the value and raises an exception if it is unknown. read(p) and read(s) both read an expression from the input port p or the string s.
release Core method
release() -> string
returns a release number of your claire system (<release>.<version>.<revision>).
restrictions Kernel method
restrictions(p:property) -> list[restriction]
returns the list of all restrictions of the property. A property is something a priori defined for all entities. A restriction is an actual definition of this property for a given class (or type).
safe Optimize method
safe(x:any) -> any
safe(x) is semantically equivalent to x and is ignored by the interpreter (x = safe(x)). On the other hand, this tells the compiler that the expression x must be compiled with the safe setting of the optimizing options. This is useful when a complete program requires high optimization settings for performance reasons but you still want to ensure that (say) overflow errors will be detected. A typical use would be
try safe( x * y) catch error MAXINT
to implement a bounded multiplication that can be placed in an optimized module.
self_print Kernel method
self_print(x:any) -> any
this is the standard method for printing unnamed objects (objects that are not in thing). It is called by default by printf on objects.
set! Core method
set!(s:collection) -> set
set!(x:integer) -> set[(0 .. 63)]
set!(s) returns an enumeration of the collection s. The result is, by definition, a set that contains exactly the members of s. An error occur if s is not finite, which can be tested with finite?(x).
set!(x) returns a set that contains all integers i such that (x / 2i) mod 2 = 1. This method considers x as the bitvector representation of a subset of (0 .. 29). The inverse is integer!.
shell Kernel method
shell(s:string) -> any
Passes the command s to the operating system (the shell).
show Reader method
show(x:any) -> any
The method show prints all the information it can possibly find about the object it has been called on: the value of all its slots are displayed. This method is called by the debugger.
shrink Kernel method
shrink(x:list,n:integer) -> list shrink(x:string,n:integer) ® string
The method shrink truncates the list or the string so that its length becomes n. This is a true side-effect and the value returned is always the same as the input. As a consequence, shrink(l,0) returns an empty list that is different from the canonical empty list nil.
sin Kernel method
sin(x:float) -> float
sin(x) returns the sine of x (x is expressed in radians).
size Core method
size(l:bag) -> integer
size(x:any) -> integer
size(l) gives the number of elements in l. If x is an abstract set (a type, a class, ...) then size(x) denotes the number of elements of type x. If the set is infinite, an exception will be raised. Note that the size of a list is not its length because of possible duplicates.
slots Kernel method
slots(c:class) -> any
slots(c) returns the list of all slots that c may have
sort Core method
sort(m:method, l:list) -> type[l]
The method sort has two arguments: an order method m such that m(x,y) = true if x <= y and a list of objects to be sorted in ascending order (according to m). The method returns the sorted list. The method is usually designated using @, as in sort(< @ integer, list(1,2,8,3,4,3)).
In CLAIRE 3, the compiler is able to “macroexpand” the definition of sort (using a quicksort algorithm) when the method is a constant and when the call to sort is used to define a single-instruction method that sorts a given list (with a void range). If we define:
SortByf(l:list<myObject>) : void -> sort(myOrder @ myObject, l)
The compiler will produce a very efficient implementation for this method through code generation, which is not a trivial feature since quicksort is doubly recursive. Notice that this optimization will only take place if:
the sort(…) message is the unique instruction of the method, which must return nothing
the sorting method is an expression of the kind (p @ class)
the list argument is the unique argument of the method
sqr Kernel method
sqr(x:integer) -> integer
sqr(x:float) -> float
returns the square of x, that is x * x.
sqrt Kernel method
sqrt(x:float) -> float
returns the square root of x. Returns an irrelevant value when x is strictly negative.
stat Kernel method
stat() -> void
stat() pretty prints the result given by mem(): it prints the memory situation of the claire system: the number of used cells and the number of remaining cells for each type of cell (chunk, small object, imported object, symbol). If the verbosity is more than 5, stat() produces a more detailed report about the way memory is used in CLAIRE.
store Kernel method
store(r1: relation, r2:relation ...) ® void
store(v: global_variable) ® void
store(a:array,n:integer,v:any,b:boolean) ® void
store(l:list,n:integer,v:any,b:boolean) ® void
store(r1,r2,...) declares the relations (properties or tables) as defeasible (using the world mechanism). If x is an array or a list, store(x,n,v,b) is equivalent to x[n] := v but also stores this update in the current world if b is true. As a syntactical convenience, the argument b may be omitted if it is true. Note that there is a similar method for properties called put_store. store(v) can be used to declare a global_variable v as defeasible (notice that only one argument is allowed).
string! Kernel method
string!(s:symbol) -> string
string!(n:integer) -> string
string!(x :float) -> string
string! converts a symbol, an integer or a float into a string. For example string!(toto) returns "toto" and string!(12) returns "12". Unlike make_string, it returns the unqualified form (string!(Francois/agenda) = “agenda", whereas make_string(Francois/agenda) = "Francois/agenda").
substitution Language method
substitution(exp:any, v:Variable, f:any) -> any
substitution(exp,v,f) returns exp where any occurrence of the free variable v is substituted by f. Hence, if occurrences(exp,v) = 0 then substitution(exp,v,f) returns exp for any f.
substring Kernel method
substring(s:string, i:integer, j:integer) -> string
substring(s1:string, s2:string, b:boolean) -> integer
substring(s,i,j) returns the substring of s starting at the ith character and ending at the jth. For example, substring("claire",3,4) returns "AI". If i is negative, the empty string is returned and if j is out of bounds (j > length(s)), then the system takes j=length(s). substring(s1,s2,b) returns i if s2 is a subsequence of s1, starting at s1's ith character. The boolean b is there to allow case-sensitiveness or not (identify 'a' and 'A' or not). When s2 cannot be identified with any subsequence of s1, the returned value is 0.
symbol! Kernel method
symbol!(s:string) -> symbol
symbol!(s:string, m:module) -> symbol
symbol!(s) returns the symbol associated to s in the claire module. For example, symbol!("toto") returns claire/«toto». symbol!(s,m) returns the symbol associated to s in the module m.
time_get, time_set, time_show, time_read Kernel method
time_get() -> integer
time_read() -> integer
time_set() -> void
time_show() -> void
time_set() starts a clock, time_get() stops it and returns an integer proportional to the elapsed time. Several such counters can be embedded since they are stored in a stack. time_show() pretty prints the result from time_get(). time_read() can be used to read the value of the time counter without stopping it.
type! Language method
type!(x:any) -> any
returns the smallest type greater than x (with respect to the inclusion order on the type lattice), that is the intersection of all types greater or equal to x.
U Core method
U(s1:set, s2:set) -> set
U(s:set, x:any) -> any
U(x:any, y:any) -> any
U(s1,s2) returns the union of the two sets. Otherwise, U returns a type which is the union of its two arguments. This constructor helps building types from elementary types.
uniform? Core method
uniform?(p:property) -> boolean
Tells if a property is uniform, that is contains only methods as restrictions, with the same types for arguments and ranges. Note that interface properties should be uniform, as well as all properties that are used dynamically in a “diet” program.
use_as_output Kernel method
use_as_output(p:port) -> port
uses_as_output(p) changes the value of the current output (the port where all print instructions will be sent) to p. It returns the previous port that was used as output which can thus be saved and possibly restored later.
vars Kernel slot
system.vars -> list[string]
system.vars contains the list of arguments passed on the shell command line (list of strings).
verbose Kernel slot
system.verbose -> integer
verbose(system) (also verbose() ) is the verbosity level that can be changed. Note that trace(i:integer) sets this slot to i.
version Kernel slot
system.version -> float
compiler.version -> float
the version if a float number (<version>.<revision>) that is part of the release number.
world?, commit,, choice, backtrack Kernel method
world?() -> integer
choice() -> void
backtrack() -> void
backtrack(n:integer) -> void
commit() -> void
backtrack0() -> void
commit(n:integer) -> void
These methods concern the version mechanism and should be used for hypothetical reasoning: each world corresponds to a state of the database. The slots s that are kept in the database are those for which store(s) has been declared. These worlds are organized into a stack, each world indexed by an integer (starting form 0). world?() returns the index of the current world; choice() creates a new world and steps into it; backtrack() pops the current world and returns to the previous one; backtrack(n) returns to the world numbered with n, and pops all the intermediary worlds. The last three methods have a different behavior since they are used to return to a previous world without forgetting what was asserted in the current world. The method commit() returns to the previous world but carries the updates that were made within the current world; these updates now belong to the previous world and another call to backtrack() would undo them. On the other hand, backtrack0() also return to the previous world, but the updates from the current world are permanently confirmed, as if they would belong to the world with index 0, which cannot be undone. Last, commit(n) returns to the world numbered with n through successive applications of commit().
write Core method
write(p:property, x:object, y:any) -> any
This method is used to store a value in a slot of an object. write(p,x,y) is equivalent to p(x) := y.