Smalltalk programming language

HomePage | Recent changes | View source | Discuss this page | Page history | Log in |

Printable version | Disclaimers | Privacy policy

Smalltalk is an dynamically typed object oriented language designed with great love and foresight at Xerox PARC, the birth place of many good things, by Adele Goldberg, Dan Ingalls, Alan Kay, Ted Kaehler and others during the 1970s. The language was generally released as Smalltalk-80 and has been very influential on many other computer languages.

Smalltalk's big ideas include:

  • Everything is an object. Strings, integers, booleans, class definitions, blocks of code, stack frames, memory; everything
  • Everything is available for modification. This means that if you don't like the way the garbage collection works, you can change it.
  • Types are dynamic -- this means that you don't have to define types in the code which makes the language much more concise.
  • Garbage collection is built in and invisible to the developer
  • Smalltalk programs are compiled to byte codes, interpreted by a virtual machine.

Here's some code to find the vowels in a string which illustrates Smalltalk's style. ( | characters declare variables, : declares parameters, and think of [ and ] as { and } curly braces for the moment):

| aString vowels |
aString := 'This is a string'.
vowels := aString select: [:aCharacter | aCharacter isVowel].

In the last line, the string is sent a select: message with the code block following as an argument. Here's the code in the superclass Collection that does the work:

| newCollection |
newCollection := self species new.
self do: [:each | 
    (aBlock value: each) 
        ifTrue: [newCollection add: each]].
^newCollection

It responds to the message by iterating through its members (this is the do: method) evaluating aBlock code once for each character; aBlock (aCharacter isVowel) when evaluated creates a boolean, which is then sent ifTrue:. If the boolean is true, the character is added to a string to be returned. Because select is defined in the abstract class Collection, we can also use it like this:

| rectangles aPoint|
rectangles := [[OrderedCollection]] 
  with: (Rectangle left: 0 right: 10 top: 100 bottom: 200)
  with: (Rectangle left: 10 right: 10 top: 110 bottom: 210).
aPoint := Point x: 20 y: 20.
collisions := rectangles select: [:aRect | aRect containsPoint: aPoint].

Isn't that great!

There are many robust Smalltalk implementations available, including:

There's even a WikiWiki implemented in Squeak Smalltalk which you can download from http://minnow.cc.gatech.edu/swiki


/Talk