Smalltalk

I never understood what the point of Smalltalk was. Perhaps that's why I had so much difficulty creating this program. I was around when Smalltalk was first introduced to the world. The two important ideas seemed to be it's size and the "message to an object" programming paradigm. It was never clear to me whether Smalltalk was supposed to be a language or an operating system. (I'm not sure that the inventors weren't equally confused.) As an OS it was supposed to be a much smaller alternative to the gigantic UNIX OS. (I'm not sure anyone but the smalltalk people thought of UNIX as being gigantic.) As a language, it was supposed to be the quintessence of object oriented programming.

In smalltalk 2 + 2 is not an arithmetic expression. Instead one is supposed to view this as a sequence of objects and messages. We have an object 2, and we send it the message + followed by the message 2. 2 responds to these messages by printing 4. Other than being a way to distiguish the enlightened from the benighted, I'm not sure that this "message to an object" paradigm has any real purpose.

The following code runs on the VisualWorks Smalltalk system. To run the code, download the SieveE.st file by clicking the link below. Open the file in the notepad. Start VisualWorks and select "new" from the "page" menu in the bottom window. Paste the Smalltalk code from SieveE.st into the resultant window, and make sure it all stays selected. Select "do it" from the Smalltalk menu, and the program output will appear in the upper window.

|Candidates i j s| Candidates := Array new: 1000 . 1 to: 1000 do: [:z| Candidates at: z put: 1 ] . Candidates at: 1 put: 0 . i := 1 . [i<1000] whileTrue: [ [i<1000 & ((Candidates at: i) = 0)] whileTrue: [i := i+1]. (i<1000) ifTrue:[ j:=2. [i*j<1000]whileTrue: [Candidates at: i*j put: 0. j:=j+1 ] ]. i := i+1. ]. s := ' is prime'. 1 to: 999 do: [:z| ((Candidates at: z) = 0) ifFalse:[ Transcript show: z printString ; show: s printString ;cr ] ] .

Click Here for the actual code.