Numbers in Smalltalk
Bijan Parsia
bparsia at email.unc.edu
Sun Dec 9 22:09:53 UTC 2001
On Sun, 9 Dec 2001, James Stark wrote:
> Hi!
>
> I have a number in a variable number called:
>
> (anumber)
Ok.
> I want to output this to a file... but smalltalk comes up with something
> about "ERROR: anString) when I put nextPutAll.
#nextPutAll: puts *collections* on the stream. So if you feed it a scalar,
it will hork and hork hard. Try #nextPut:
> It does it with strings ok,
Strings are collections (of characters, to be precise).
> but with numbers it will not output to a file, any suggestions?
There are at least two issues here: Writing objects to streams, and
writing objects to files (via a stream). The first involves the difference
between #nextPut: and #nextPutAll:. The second involves what the file is
expecting and what marshalling/serialization you want to do.
> is a number
> a byte?
No. Never. Good thing too.
Of course you can *encode* Numbers in a variety of ways.
> I actually convert from String to Numbers using "anNumber" method.... how do
> you convert the number back to being a string?
Typically, using something like #readFrom: and #readFrom:base: but there
are other methods (even some in String) if you can make certain
assumptions about your input.
> since when I convert floats
> to numbers they are fraction... I want to get them back again... how do I do
> that?
Try #asFloat:
(3/4) asFloat
> Any suggestions would be welcome since I am finding it hard to program in
> Smalltalk since it seems to take the pinciple of oo to the extreme!
Actually, it *does* take it to rather an extreme, not merely seems to.
But I seriously doubt that that's the problem at the moment.
Reading a tutorial might help, just if it familiarizes you 1) with the
basics of a Smalltalk system and 2) with the tools you need to explore
one.
Cheers,
Bijan Parsia.
More information about the Squeak-dev
mailing list
|