| Did you know ... | Search Documentation: |
| Send methods |
|function->append->append
object to chain if it is not already a member of it.
->member ->append?- new(@ch, chain(aap, noot, mies)). ?- send(@ch, after, noot, aap) --> yes ?- send(@ch, after, aap, mies) --> no
Fails if one of the arguments is not in the chain.
->beforeNote that chains may contain duplicates.
->add ->_append->after.
->move_before ->after<-head_cell
or chain<-next_cell.
One should try to avoid using this function.
<-cell_value <-head_cell <-next_cellcurrent cell with the argument.
Diagnostics: Fails without modifiying the current element if the index is out of range.
<-nth1object from the chain. Fails
if there is no such object. Note that objects are compared by their
object identity; not by their contents. Hence, the following fails
because the second point is a different instance.
?- new(@ch, chain(point(6,6))). Yes ?- send(@ch, delete, point(6,6)). No
See also chain->delete_all
and chain->subtract.
->delete_all->delete.
->delete<-head
and
chain<-delete_head.
Diagnostics: Fails if the chain is empty.
Diagnostics: Fails if the chain is empty.
<-current
if code is executed with success. Fails otherwise. Arguments:
@arg1 The (current) element @arg2 1-based index of element
New code should consider using chain<-find,
which avoids the usage of chain<-current.
->for_all <-find
@arg1 Current element. @arg2 Index of the element (1-based)
The iteration stops with failure if the execution of code
fails for some element of the chain.
In the example below we print the elements of a chain on the terminal:
?- new(@ch, chain(hello, world)). ?- send(@ch, for_all, message(@pce, write_ln, @arg1)). hello world
If the safe argument is @on
(default), the elements of the chain are first copied to a local array
and existence of the objects in the elements is tested prior to
executing the code
object. This implies that the chain may be modified by the execution of
the method and new elements will not be seen. If this argument is @off
this method iterates over the chain itself. In this case it is not
allowed to modify the chain.
Defaults: By default this operation is caried-out safe
(= @on).
<-find_all <-find ->find ->for_some ->for_all ->for_all->for_all,
but continues the iteration even if code fails to execute for some
element. Always succeeds. Forwarded arguments:
@arg1 element @arg2 1-based index of element
->for_all<-current.
Use of chain<-current
is discouraged and new code must consider using chain->insert_before.
->move_before ->move_before<-member
of the chain, value is chain->append’ed.
See also chain->insert_after.
->addvalue
is made the chain<-head
of the chain.
See also chain->move_before.
->move_before ->move_after->member
or they are equal. To move an element to the start of the chain, you may
use either of:
?- ignore(send(Ch, move_before, Element, Ch?head)). ?- send(Ch, move_after, Element).
See also chain->move_after, chain->before
and chain->after.
Diagnostics: Fails silently if either argument is not a chain->member
of the chain.
->insert ->before ->insert_after ->move_after|function],
unique=[bool]code is a function
object, the return status is interpreted as follows:
smaller
@arg1 must be
before @arg2equal Both elements are equal (neither is
deleted, but their order is undefined).Common code objects to use are the arithmetic comparison objects and messages invoking a string comparison method. Examples:
Sort a chain of integers, lowest first:
send(Chain, sort, @arg1 < @arg2).
Sort a chain of char_array objects, alphabetically lowest first:
send(Chain, sort, ?(@arg1, compare, @arg2)).
If compare code is omitted, the contents of the chain is
sorted on alphabetically on their object<-print_name.
If unique equals @on,
duplicates (i.e. pairs of objects for which
executing the comparison yields equal) will be removed.
Default is not to remove duplicates. See also chain->unique.
NOTE: When sorting with a non-function, the result of comparing two
element is a boolean and cannot express equal.
chain->sort
yields an undefined result if the chain contains two or more element for
which code->forward and
code->forward
yield the same result. This undefined behaviour can include a fatal
error.
<-compare ->smaller ->larger ->sort->delete_all.->sort
and chain->add.->clear
to remove the cells.