Thomas said:
....which BTW I think is sensible. A BigInteger of 5 is like the number
5. You shouldn't (at least in java) be able to say 5.add(4), and have 5
be 9.
BTW, does smalltalk allow that?
No, they are normally treated as immutable in Smalltalk. However they do
understand the normal arithmetic operations, so you write:
x := y + z.
just as for small integers.
(You /can/ modify them in place, but it's not good style to do so, and anyway
the arithmetic operations don't exist at that level -- you are just treating
them as arrays of bytes)
As an aside/advert, in Smalltalk all integers share a common superclass,
Integer, and the optimised (roughly equivalent to machine-native) SmallInteger
and unbounded LargeInteger are subclasses of that. In normal circumstances
they are treated completely uniformly (in fact portable code cannot assume the
existence of either subclass). One effect of that is that there are never any
truncation/wraparound/overflow issues in Smalltalk integer arithmetic[*]. One
of the things that I think the Java designers got wrong was not following that
pattern -- at least to the extent of making primitive arithmetical types an
/optimisation/ available to skilled programmers, rather than forcing them down
everybody's throat as the default.
[*] of course, Smalltalk is not the only "grown-up" language with this
property -- which makes the Java choice even less forgivable.
-- chris