A number object
represents an integer just like the primitive type
int. Numbers are more costly, but allow for some operations
such as comparison or addition.
Instances of class number are commonly used to implement counters:
count_instances(Device, Class, Instances) :-
new(I, number(0)),
send(Device, for_all, @default,
if(message(@arg1, instance_of, Class),
message(I, plus, 1))),
get(I, value, Instances),
send(I, done).
See also class real.
int and thus limited to the
range
`@pce <-min_integer` .. `@pce <-min_integer`
|number|number|number|numberaccumulators
(see the various examples in this class). Functions are more convenient
in expressions.|number|real?- send(number(1), equal, 1). ?- send(number(1), equal, 1.0). ?- send(number(1), equal, number(1)). ?- send(number(1), equal, '1').
|number|real|number|real|number|real|number|real|number|real->larger, number->smaller,
...} than the argument.|number|number<-value
to the {number->maximum, number->minimum}
of the current number<-value
and the argument. Useful in may computations. Suppose Chain is a
chain holding string and we which to know the widest string given the
font
Font:
width_of_strings(Chain, Font, Width) :-
new(W, number(0)),
send(Chain, for_all,
message(W, maximum, ?(Font, width, @arg1))),
get(W, value, Width),
send(W, done).
send operations available as get operations so
that the receiving number is not modified:
?- new(N, number(2)), get(N, plus, 3, N2), get(N2, value, V2). V2 = 5 N2 = @1687003/number N = @1686999/number
First creates a new number
object with the same number<-value,
invokes the method as a send method and, if the send succeeds, returns
the copy.
|number|real -> {smaller,equal,larger}smaller implies the
receiver is smaller than the argument. Intended to support chain->sort
and friends. To sort a chain of integers by value:
send(Chain, sort, ?(@arg1, compare, @arg2)).