Content-Type: text/html

# Smalltalk

HomePage | RecentChanges | Preferences
You can edit this page right now! It's a free, community project

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 code]?s, 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:

- CinCom? VisualWorks?, which is a direct descendent of Xerox's work, see http://www.cincom.com/scripts/smalltalk.exe/downloads/index.asp
- IBM's VisualAge? for Smalltalk, see http://www-4.ibm.com/software/ad/smalltalk/
- Dolphin Smalltalk, see http://www.object-arts.com/Home.htm
- Smalltalk/X, see http://www.exept.de/exept_99/english/welcomeFrame_smalltalk.html
- Squeak, see http://www.squeak.org
- Pocket Smalltalk which runs on a Palm Pilot, see http://www.pocketsmalltalk.com/new/

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

HomePage | RecentChanges | Preferences
You can edit this page right now! It's a free, community project
Edit text of this page | View other revisions
Last edited July 30, 2001 5:58 am (diff)
Search: