| Communication ports | categories I/O, Modules and System Interface Printing |
WCL syntax |
There are several ways of printing in CLAIRE. Any entity may be printed with the function print. When print is called for an object that does not inherit from thing (an object without a name), it calls the method self_print of which you can define new restrictions whenever you define new classes. If self_print was called on an object x owned by a class toto for which no applicable restriction could be found, it would print <toto>.
In the case of bags (sets or lists), strings, symbols or characters, the standard method is princ. It formats its argument in a somewhat nicer way than print. For example :
| print("john") prints "john" princ("john") prints john |
| printf("~S is ~A and here is what we know\n ~I", john, 23, show(john)) |
| (print(john), princ(" is "), princ(23), princ(" and here is what we know\n"), show(john)) |
| let p := fopen("agenda-2006", "w") in (use_as_output(p), write(agenda), fclose(p)) |
| printf(my_port, "~S is ~A and here is what we know\n ~I", john, 23, show(john)) |
| let old := use_as_output(my_port) in (print(john), princ(" is "), princ(23), princ(" and here is what we know\n"), show(john), use_as_output(old)) |
All trace statements will be directed to this port. A trace statement is either obtained implicitly through tracing a method or a rule, or explicitly with the trace statement. the statement trace(n, <string>, <args> ...) is equivalent to printf(<string>, <args> ..) with two differences: the string is printed only if the verbosity level verbose() is higher than n and the output port is ctrace(). The following lines are equivalent :
| trace(0, "assigning ~S with ~S", x, y) //[0] assigning ~S with ~S // x, y (if (verbose() >= 0) printf(ctrace(), "assigning ~S with ~S", x, y)) |
| categories | Printing | normal dispatch | Core method |
end_of_string() returns the string containing everything that has been printed since the last call to print_in_string().
| categories | Printing | normal dispatch | Core method |
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. Unlike with the printf construction ~I cannot be used in a format. Last the string s may contain color escapes.
| categories | Printing | normal dispatch | Kernel method |
equivalent to print(n)
| categories | Printing | normal dispatch | Kernel method |
princ(s) prints the string s on the current output (cout()).
| categories | Printing | normal dispatch | Kernel method |
princ(c) prints the char c on the current output (cout()).
| categories | Printing | normal dispatch | Kernel method |
prints the content of the bag l on the current output (cout()). elements are separated by a comma ','.
| categories | Printing | normal dispatch | [XL] Kernel method |
princ(s,i,j) is equivalent to princ(substring(s,i,j)) but without the allocation of a temporary string
| categories | Printing | normal dispatch | Kernel method |
prints the entity x (x can be anything) on the current output (cout()).
| categories | Printing | normal dispatch | Core method |
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. print_in_string may be used recursively.
| categories | Printing | normal dispatch | Kernel interface |
self_print interface is used to redefine the way an entity is printed by the standard print method. self_print can be redefined for each new created class, for instance :
| account <: ephemeral_object(account_id:integer) self_print(self:account) : void -> printf("<account with id ~S>", self.account_id) |