(redirected from Smalltalk)

[Home]Smalltalk programming language

HomePage | Recent Changes | Preferences

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:

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?

HomePage | Recent Changes | Preferences
This page is read-only | View other revisions
Last edited October 17, 2001 9:41 pm by Drj (diff)
Search: