Practical Smalltalk

February 4, 2011

QuickSilver Smalltalk is implemented completely in JavaScript and produces compiled output for the JavaScript environment.

In JavaScript, all types of numbers are represented in 64-bit floating-point format whose “prototype” is “Number”. The QuickSilver compiler (see the ImageBuilder class in version 0.2) does the following:

Number.prototype.klass = Smalltalk.classes.numberClass;

Which means that any number generated by JavaScript will have a “klass” attribute which references the QuickSilver class hierarchy. It is a technique works very well and ensures that any JavaScript number has the proper Smalltalk class.

However, as I said above, both integer and decimal numbers will have the same “Number” class.

In Squeak, “Number” is an abstract class with several concrete subclasses such as “Float”, “Fraction”, “Integer”, and “ScaledDecimal”; and “Integer” itself has the subclasses “LargePositiveInteger”, “LargeNegativeInteger”, and “SmallInteger”.

In some architectures there may be a performance advantage to using say “SmallInteger” instead of “Integer” or “Integer” instead of “Float”. I am certain that the designers of Squeak had valid reasons for creating multiple number representations.

But in a JavaScript environment *all* numbers are 64-bit floating-point – if you add “2+2” you are (presumably) doing 64-bit arithmetic.

That is why in QuickSilver there is only a single class for numbers which is called “Number”. Because, in JavaScript, numbers have only a single representation internally.


4 Responses to “Practical Smalltalk”

  1. Steffen Says:

    Schmalltalk’s number hierarchy actually allows to do arithmetic without caring about limitations of a n-bit number representation. It simply switches between hardware and software arithmetics if necessary, at least for integers and fractions. Do you plan to port that nice feature too?

    • Peter Fisk Says:

      Hi Steffen,

      I don’t plan to port fractions because in 24 years of using Smalltalk, I have never found a reason to use them.

      QuickSilver is implemented in JavaScript which already has numeric libraries for every platform.

      There is nothing that needs to be added.

      — Peter

  2. Smalltalker Says:

    Peter, very good job all you’re doing !!!

    I propose to rename .klass (#klass) by .stClass (#stClass) what do you think?



  3. Peter Fisk Says:

    Hi Smalltalker,

    That sounds like a good idea.

    It should be added as a feature change to the QuickSilver Smalltalk project on Google.

    — Peter

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: