[   ^ to index...   |   next -->   ]

CSE 341 : 10 May 2001

Smalltalk: the language

Smalltalk is small and simple. Like Scheme, it demonstrates the principle that power comes not from piling feature upon feature, but from pruning away restrictions.

Everything in Smalltalk is an object. Objects have a class, some instance variables, and methods, all of which are ultimately objects. All actions are performed by sending a message to an object; if the object has a method for handling that message, the method is executed.

Bindings

Objects are assigned/bound to names by using the assignment statement:

    x := 'hi'.

Here, we are binding x to the String object representing 'hi'. Differences relative to ML:

Message sending syntax

    x negated.       "Unary message syntax"
    x + 5.           "Infix message syntax"
    x gcd: 21.       "Keyword message syntax"

    "Keyword message with multiple arguments"
    'Hello, world' replaceFrom: 1 to: 6 with: 'byebye' startingAt: 1.

In keyword syntax, each argument to a message follows a keyword. This only seems weird because you are used to memorizing the argument order from languages like C. Since each keyword describes the argument that follows, I find this nicer than "normal" function syntax.

Common syntax gotchas


Keunwoo Lee
Last modified: Thu May 10 00:30:56 PDT 2001