Smalltalk
Encyclopedia
Smalltalk is an object-oriented
, dynamically typed
, reflective
programming
language
. Smalltalk was created as the language to underpin the "new world" of computing exemplified by "human–computer symbiosis." It was designed and created in part for education
al use, more so for constructionist learning
, at the Learning Research Group (LRG) of Xerox PARC by Alan Kay
, Dan Ingalls, Adele Goldberg
, Ted Kaehler, Scott Wallace, and others during the 1970s.
The language was first generally released as Smalltalk-80. Smalltalk-like languages are in continuing active development, and have gathered loyal communities of users around them. ANSI Smalltalk was ratified in 1998 and represents the standard version of Smalltalk.
Smalltalk was the product of research led by Alan Kay
at Xerox Palo Alto Research Center (PARC); Alan Kay designed most of the early Smalltalk versions, which Dan Ingalls implemented. The first version, known as Smalltalk-71, was created by Ingalls in a few mornings on a bet that a programming language based on the idea of message passing
inspired by Simula
could be implemented in "a page of code." A later variant actually used for research work is now known as Smalltalk-72 and influenced the development of the Actor model
. Its syntax and execution model were very different from modern Smalltalk variants.
After significant revisions which froze some aspects of execution semantics to gain performance (by adopting a Simula
-like class inheritance model of execution), Smalltalk-76 was created. This system had a development environment
featuring most of the now familiar tools, including a class library code browser/editor. Smalltalk-80 added metaclass
es, to help maintain the "everything is an object" (except private instance variables) paradigm by associating properties and behavior with individual classes, and even primitives such as integer and boolean values (for example, to support different ways of creating instances).
Smalltalk-80 was the first language variant made available outside of PARC, first as Smalltalk-80 Version 1, given to a small number of firms (Hewlett-Packard
, Apple Computer
, Tektronix
, and DEC
) and universities (UC Berkeley) for "peer review" and implementation on their platforms. Later (in 1983) a general availability implementation, known as Smalltalk-80 Version 2, was released as an image (platform-independent file with object definitions) and a virtual machine
specification. ANSI Smalltalk has been the standard language reference since 1998.
Two of the currently popular Smalltalk implementation variants are descendants of those original Smalltalk-80 images. Squeak
is an open source
implementation derived from Smalltalk-80 Version 1 by way of Apple Smalltalk. VisualWorks
is derived from Smalltalk-80 version 2 by way of Smalltalk-80 2.5 and ObjectWorks (both products of ParcPlace Systems, a Xerox PARC spin-off company formed to bring Smalltalk to the market). As an interesting link between generations, in 2002 Vassili Bykov implemented Hobbes, a virtual machine running Smalltalk-80 inside VisualWorks. (Dan Ingalls later ported Hobbes to Squeak.)
During the late 1980s to mid-1990s, Smalltalk environments — including support, training and add-ons — were sold by two competing organizations: ParcPlace Systems and Digitalk, both California based. ParcPlace Systems tended to focus on the Unix/Sun Microsystems market, while Digitalk focused on Intel-based PCs running Microsoft Windows or IBM's OS/2. Both firms struggled to take Smalltalk mainstream due to Smalltalk's substantial memory needs, limited run-time performance, and initial lack of supported connectivity to SQL
-based relational database servers. While the high price of ParcPlace Smalltalk limited its market penetration to mid-sized and large commercial organizations, the Digitalk products initially tried to reach a wider audience with a lower price. IBM initially supported the Digitalk product, but then entered the market with a Smalltalk product in 1995 called VisualAge/Smalltalk. Easel introduced Enfin at this time on Windows and OS/2. Enfin became far more popular in Europe, as IBM introduced it into IT shops before their development of IBM Smalltalk (later VisualAge). Enfin was later acquired by Cincom Systems, and is now sold under the name ObjectStudio, and is part of the Cincom Smalltalk product suite.
In 1995, ParcPlace and Digitalk merged into ParcPlace-Digitalk and then rebranded in 1997 as ObjectShare, located in Irvine, CA. ObjectShare (NASDAQ
: OBJS) was traded publicly until 1999, when it was delisted and dissolved. The merged firm never managed to find an effective response to Java as to market positioning, and by 1997 its owners were looking to sell the business. In 1999, Seagull Software acquired the ObjectShare Java development lab (including the original Smalltalk/V and Visual Smalltalk development team), and still owns VisualSmalltalk, although worldwide distribution rights for the Smalltalk product remained with ObjectShare who then sold them to Cincom
. VisualWorks was sold to Cincom
and is now part of Cincom Smalltalk. Cincom has backed Smalltalk strongly, releasing multiple new versions of VisualWorks and ObjectStudio each year since 1999.
Cincom
, Gemstone and Object Arts, plus other vendors continue to sell Smalltalk environments. IBM has 'end of life'd VisualAge Smalltalk having in the late 1990s decided to back Java and it is, , supported by Instantiations, Inc. which has renamed the product VA Smalltalk and released several new versions. The open Squeak
implementation has an active community of developers, including many of the original Smalltalk community, and has recently been used to provide the Etoys environment on the OLPC project, a toolkit for developing collaborative applications Croquet Project
, and the Open Cobalt
virtual world application. GNU Smalltalk
is a free software
implementation of a derivative of Smalltalk-80 from the GNU
project. Last but not least Pharo Smalltalk
(a fork of Squeak
oriented towards research and use in commercial environments) a new and clean MIT licensed open source Smalltalk that brings fresh ideas and interest into the Smalltalk market and scene.
A significant development, that has spread across all current Smalltalk environments, is the increasing usage of two web frameworks, Seaside and AIDA/Web
, to simplify the building of complex web applications. Seaside has seen considerable market interest with Cincom, Gemstone and Instantiations incorporating and extending it.
Smalltalk has influenced the wider world of computer programming in four main areas. It inspired the syntax and semantics of other computer programming languages. Secondly, it was a prototype for a model of computation
known as message passing
. Thirdly, its WIMP
GUI
inspired the windowing environments of personal computers in the late twentieth and early twenty-first centuries, so much so that the windows of the first Macintosh
desktop look almost identical to the MVC windows of Smalltalk-80. Finally, the integrated development environment
was the model for a generation of visual programming tools that look like Smalltalk's code browsers and debuggers.
Python
and Ruby
have reimplemented some Smalltalk ideas in an environment similar to that of AWK or Perl
. The Smalltalk "metamodel" also serves as the inspiration for the object model design of Perl 6
.
The syntax and runtime behaviour of the Objective-C
programming language is strongly influenced by Smalltalk.
There is also a modular Smalltalk-like implementation designed for scripting called S#
, or Script.NET. S# uses just-in-time compilation
technology and supports an extended Smalltalk-like language written by David Simmons of Smallscript Corp.
Several programming languages like Self and lately Newspeak
have taken the whole idea of Smalltalk in new directions
A Smalltalk object can do exactly three things:
The state an object holds is always private to that object. Other objects can query or change that state only by sending requests (messages) to the object to do so. Any message can be sent to any object: when a message is received, the receiver determines whether that message is appropriate. Alan Kay has commented that despite the attention given to objects, messaging is the most important concept in Smalltalk: "The big idea is 'messaging' -- that is what the kernel of Smalltalk/Squeak is all about (and it's something that was never quite completed in our Xerox PARC phase)."
Smalltalk is a "pure" object-oriented programming language, meaning that, unlike Java
and C++
, there is no difference between values which are objects and values which are primitive types. In Smalltalk, primitive values such as integers, booleans and characters are also objects, in the sense that they are instances of corresponding classes, and operations on them are invoked by sending messages. A programmer can change the classes that implement primitive values, so that new behavior can be defined for their instances—for example, to implement new control structures—or even so that their existing behavior will be changed. This fact is summarized in the commonly heard phrase "In Smalltalk everything is an object", which may be more accurately expressed as "all values are objects", as variables are not.
Since all values are objects, classes
themselves are also objects. Each class is an instance of the metaclass
of that class. Metaclasses in turn are also objects, and are all instances of a class called Metaclass. Code blocks are also objects.
system, implemented in Smalltalk-80 itself. Smalltalk-80 provides both structural and computational reflection. Smalltalk is a structurally reflective system whose structure is defined by Smalltalk-80 objects. The classes and methods that define the system are themselves objects and fully part of the system that they help define. The Smalltalk compiler compiles textual source code into method objects, typically instances of
Since the classes are themselves objects, they can be asked questions such as "what methods do you implement?" or "what fields/slots/instance variables do you define?". So objects can easily be inspected, copied, (de)serialized
and so on with generic code that applies to any object in the system.
Smalltalk-80 also provides computational reflection, the ability to observe the computational state of the system. In languages derived from the original Smalltalk-80 the current activation of a method is accessible as an object named via a pseudo-variable (one of the six reserved words),
or Prolog
-like back-tracking without modifying the virtual machine. The exception system is implemented using this facility. One of the more interesting uses of this is in the Seaside web framework which relieves the programmer of dealing with the complexity of a Web Browser's back button by storing continuations for each edited page and switching between them as the user navigates a web site. Programming the web server using Seaside can then be done using a more conventional programming style.
When an object is sent a message that it does not implement, the virtual machine sends the object the
of the message as an argument. The message (another object, an instance of
Another important use of
from any other class. The instances of this class effectively understand no messages. So every time a message is sent to these instances they actually get sent
, COM+
and RMI
but first pioneered in Smalltalk-80 in the 1980s), and persistent systems where changes in state are written to a database
and the like. An example of this latter is Logic Arts' VOSS (Virtual Object Storage System) available for VA Smalltalk under dual open source
and commercial licensing.
instances.
Numbers. The following list illustrates some of the possibilities.
The last two entries are a binary and a hexadecimal number, respectively. The number before the 'r' is the radix
or base. The base does not have to be a power of two; for example 36rSMALLTALK is a valid number equal to 80738163270632 decimal.
Characters are written by preceding them with a dollar sign:
Strings are sequences of characters enclosed in single quotes:
To include a quote in a string, escape it using a second quote:
Double quotes do not need escaping, since single quotes delimit a string:
Two equal strings (strings are equal if they contain all the same characters) can be different objects residing in different places in memory. In addition to strings, Smalltalk has a class of character sequence objects called Symbol. Symbols are guaranteed to be unique—there can be no two equal symbols which are different objects. Because of that, symbols are very cheap to compare and are often used for language artifacts such as message selectors (see below).
Symbols are written as # followed by a string literal. For example:
Selectors are written as # followed by characters. For example:
The ANSI Smalltalk standard permits implementations to, and most implementations do, use the same type for symbols and selectors, and make them equivalent. So in most implementations the above two are equivalent.
Arrays:
defines an array of four integers.
Many implementations support the following literal syntax for ByteArrays:
defines a ByteArray of four integers.
And last but not least, blocks (anonymous function
literals)
Blocks are explained in detail further in the text.
Many Smalltalk dialects implement additional syntaxes for other objects, but the ones above are the essentials supported by all.
has class shared variables and namespace shared variables, while Squeak
and many other implementations have class variables, pool variables and global variables.
Temporary variable declarations in Smalltalk are variables declared inside a method (see below). They are declared at the top of the method as names separated by spaces and enclosed by vertical bars. For example:
declares a temporary variable named index. Multiple variables may be declared within one set of bars:
declares two variables: index and vowels.
Assigns the string 'aeiou' to the previously declared vowels variable. The string is an object (a sequence of characters between single quotes is the syntax for literal strings), created by the compiler at compile time.
In the original Parc Place image, the glyph of the underscore character (_) appeared as a left-facing arrow. Smalltalk originally accepted this left-arrow as the only assignment operator. Some modern code still contains what appear to be underscores acting as assignments, harking back to this original usage. Most modern Smalltalk implementations accept either the underscore or the colon-equals syntax.
, single dynamic message dispatch
strategy (as contrasted to a synchronous, multiple dispatch
strategy adopted by some other object-oriented languages).
The following example sends the message 'factorial' to number 42:
In this situation 42 is called the message receiver, while 'factorial' is the message selector. The receiver responds to the message by returning a value (presumably in this case the factorial
of 42). Among other things, the result of the message can be assigned to a variable:
"factorial" above is what is called a unary message because only one object, the receiver, is involved. Messages can carry additional objects as arguments, as follows:
In this expression two objects are involved: 2 as the receiver and 4 as the message argument. The message result, or in Smalltalk parlance, the answer is supposed to be 16. Such messages are called keyword messages. A message can have more arguments, using the following syntax:
which answers the index of character 'o' in the receiver string, starting the search from index 6. The selector of this message is "indexOf:startingAt:", consisting of two pieces, or keywords.
Such interleaving of keywords and arguments is meant to improve readability of code, since arguments are explained by their preceding keywords. For example, an expression to create a rectangle using a C++ or Java-like syntax might be written as:
It's unclear which argument is which. By contrast, in Smalltalk, this code would be written as:
The receiver in this case is "Rectangle", a class, and the answer will be a new instance of the class with the specified width and height.
Finally, most of the special (non-alphabetic) characters can be used as what are called binary messages. These allow mathematical and logical operators to be written in their traditional form:
which sends the message "+" to the receiver 3 with 4 passed as the argument (the answer of which will be 7). Similarly,
is the message ">" sent to 3 with argument 4 (the answer of which will be false).
Notice, that the Smalltalk-80 language itself does not imply the meaning of those operators. The outcome of the above is only defined by how the receiver of the message (in this case a Number instance) responds to messages "+" and ">".
A side effect of this mechanism is operator overloading. A message ">" can also be understood by other objects, allowing the use of expressions of the form "a > b" to compare them.
is evaluated as follows:
The answer of the last message sent is the result of the entire expression.
Parentheses can alter the order of evaluation when needed. For example,
will change the meaning so that the expression first computes "3 factorial + 4" yielding 10. That 10 then receives the second "factorial" message, yielding 3628800. 3628800 then receives "between:and:", answering false.
Note that because the meaning of binary messages is not hardwired into Smalltalk-80 syntax, all of them are considered to have equal precedence and are evaluated simply from left to right. Because of this, the meaning of Smalltalk expressions using binary messages can be different from their "traditional" interpretation:
is evaluated as "(3 + 4) * 5", producing 35. To obtain the expected answer of 23, parentheses must be used to explicitly define the order of operations:
Unary messages can be chained by writing them one after another:
which sends "factorial" to 3, then "factorial" to the result (6), then "log" to the result (720), producing the result 2.85733.
A series of expressions can be written as in the following (hypothetical) example, each separated by a period. This example first creates a new instance of class Window, stores it in a variable, and then sends two messages to it.
If a series of messages are sent to the same receiver as in the example above, they can also be written as a cascade with individual messages separated by semicolons:
This rewrite of the earlier example as a single expression avoids the need to store the new window in a temporary variable. According to the usual precedence rules, the unary message "new" is sent first, and then "label:" and "open" are sent to the answer of "new".
Where :params is the list of parameters the code can take. This means that the Smalltalk code:
can be understood as:
:
or expressed in lambda terms as:
:
and
can be evaluated as
Or in lambda terms as:
The resulting block object can form a closure
: it can access the variables of its enclosing lexical scopes at any time. Blocks are first-class object
s.
Blocks can be executed by sending them the value message (compound variations exist in order to provide parameters to the block e.g. 'value:value:' and 'valueWithArguments:').
The literal representation of blocks was an innovation which on the one hand allowed certain code to be significantly more readable; it allowed algorithms involving iteration to be coded in a clear and concise way. Code that would typically be written with loops in some languages can be written concisely in Smalltalk using blocks, sometimes in a single line. But more importantly blocks allow control structure to be expressed using messages and polymorphism, since blocks defer computation and polymorphism can be used to select alternatives. So if-then-else in Smalltalk is written and implemented as
Note that this is related to functional programming
, wherein patterns of computation (here selection) are abstracted
into higher-order function
s. For example, the message select: on a Collection is equivalent to the higher-order function filter
on an appropriate functor
.
The following code demonstrates this:
Blocks are also used to implement user-defined control structures, enumerators, visitors, pluggable behavior and many other patterns.
For example:
In the last line, the string is sent the message select: with an argument that is a code block literal. The code block literal will be used as a predicate function that should answer true if and only if an element of the String should be included in the Collection of characters that satisfy the test represented by the code block that is the argument to the "select:" message.
A String object responds to the "select:" message by iterating through its members (by sending itself the message "do:"), evaluating the selection block ("aBlock") once with each character it contains as the argument. When evaluated (by being sent the message "value: each"), the selection block (referenced by the parameter "aBlock", and defined by the block literal "[:aCharacter | aCharacter isVowel]"), answers a boolean, which is then sent "ifTrue:". If the boolean is the object true, the character is added to a string to be returned.
Because the "select:" method is defined in the abstract class Collection, it can also be used like this:
Often, most of this definition will be filled in by the environment. Notice that this is actually a message to the "Object"-class to create a subclass called "MessagePublisher". In other words: classes are first-class object
s in Smalltalk which can receive messages just like any other object and can be created dynamically at execution time.
The following method demonstrates receiving multiple arguments and returning a value:
The method's name is
Note that objects are responsible for determining dynamically at runtime which method to execute in response to a message—while in many languages this may be (sometimes, or even always) determined statically at compile time.
creates (and returns) a new instance of the MessagePublisher class. This is typically assigned to a variable:
However, it is also possible to send a message to a temporary, anonymous object:
Note that a Transcript window would need to be open in order to see the results of this example.
Many Smalltalk systems, however, do not differentiate between program data (objects) and code (classes). In fact, classes are objects themselves. Therefore most Smalltalk systems store the entire program state (including both Class and non-Class objects) in an image
file. The image can then be loaded by the Smalltalk virtual machine
to restore a Smalltalk-like system to a prior state. This was inspired by FLEX, a language created by Alan Kay
and described in his M.Sc. thesis.
Other languages that model application code as a form of data, such as Lisp, often use image-based persistence as well.
Smalltalk images are similar to (restartable) core dump
s and can provide the same functionality as core dumps, such as delayed or remote debugging with full access to the program state at the time of error.
can be changed in a running system without restarting it. In some implementations, the syntax of the language or the garbage collection
implementation can also be changed on the fly
. Even the statement
, which is then interpreted by a virtual machine
or dynamically translated into machine-native code.
Object-oriented programming
Object-oriented programming is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their interactions – to design applications and computer programs. Programming techniques may include features such as data abstraction,...
, dynamically typed
Type system
A type system associates a type with each computed value. By examining the flow of these values, a type system attempts to ensure or prove that no type errors can occur...
, reflective
Reflection (computer science)
In computer science, reflection is the process by which a computer program can observe and modify its own structure and behavior at runtime....
programming
Computer programming
Computer programming is the process of designing, writing, testing, debugging, and maintaining the source code of computer programs. This source code is written in one or more programming languages. The purpose of programming is to create a program that performs specific operations or exhibits a...
language
Programming language
A programming language is an artificial language designed to communicate instructions to a machine, particularly a computer. Programming languages can be used to create programs that control the behavior of a machine and/or to express algorithms precisely....
. Smalltalk was created as the language to underpin the "new world" of computing exemplified by "human–computer symbiosis." It was designed and created in part for education
Education
Education in its broadest, general sense is the means through which the aims and habits of a group of people lives on from one generation to the next. Generally, it occurs through any experience that has a formative effect on the way one thinks, feels, or acts...
al use, more so for constructionist learning
Constructionist learning
Constructionist learning is inspired by the constructivist theory that individual learners construct mental models to understand the world around them. However, constructionism holds that learning can happen most effectively when people are also active in making tangible objects in the real world...
, at the Learning Research Group (LRG) of Xerox PARC by Alan Kay
Alan Kay
Alan Curtis Kay is an American computer scientist, known for his early pioneering work on object-oriented programming and windowing graphical user interface design, and for coining the phrase, "The best way to predict the future is to invent it."He is the president of the Viewpoints Research...
, Dan Ingalls, Adele Goldberg
Adele Goldberg (computer scientist)
Adele Goldberg is a computer scientist who participated in the development of the programming language Smalltalk-80 and various concepts related to object oriented programming while a researcher at the Xerox Palo Alto Research Center, PARC, in the 1970s.Goldberg began working at PARC in 1973, and...
, Ted Kaehler, Scott Wallace, and others during the 1970s.
The language was first generally released as Smalltalk-80. Smalltalk-like languages are in continuing active development, and have gathered loyal communities of users around them. ANSI Smalltalk was ratified in 1998 and represents the standard version of Smalltalk.
History
There are a large number of Smalltalk variants. The unqualified word Smalltalk is often used to indicate the Smalltalk-80 language, the first version to be made publicly available and created in 1980.Smalltalk was the product of research led by Alan Kay
Alan Kay
Alan Curtis Kay is an American computer scientist, known for his early pioneering work on object-oriented programming and windowing graphical user interface design, and for coining the phrase, "The best way to predict the future is to invent it."He is the president of the Viewpoints Research...
at Xerox Palo Alto Research Center (PARC); Alan Kay designed most of the early Smalltalk versions, which Dan Ingalls implemented. The first version, known as Smalltalk-71, was created by Ingalls in a few mornings on a bet that a programming language based on the idea of message passing
Message passing
Message passing in computer science is a form of communication used in parallel computing, object-oriented programming, and interprocess communication. In this model, processes or objects can send and receive messages to other processes...
inspired by Simula
Simula
Simula is a name for two programming languages, Simula I and Simula 67, developed in the 1960s at the Norwegian Computing Center in Oslo, by Ole-Johan Dahl and Kristen Nygaard...
could be implemented in "a page of code." A later variant actually used for research work is now known as Smalltalk-72 and influenced the development of the Actor model
Actor model
In computer science, the Actor model is a mathematical model of concurrent computation that treats "actors" as the universal primitives of concurrent digital computation: in response to a message that it receives, an actor can make local decisions, create more actors, send more messages, and...
. Its syntax and execution model were very different from modern Smalltalk variants.
After significant revisions which froze some aspects of execution semantics to gain performance (by adopting a Simula
Simula
Simula is a name for two programming languages, Simula I and Simula 67, developed in the 1960s at the Norwegian Computing Center in Oslo, by Ole-Johan Dahl and Kristen Nygaard...
-like class inheritance model of execution), Smalltalk-76 was created. This system had a development environment
Development environment
In hosted software development, a development environment refers to a server tier designated to a specific stage in a release process....
featuring most of the now familiar tools, including a class library code browser/editor. Smalltalk-80 added metaclass
Metaclass
In object-oriented programming, a metaclass is a class whose instances are classes. Just as an ordinary class defines the behavior of certain objects, a metaclass defines the behavior of certain classes and their instances. Not all object-oriented programming languages support metaclasses...
es, to help maintain the "everything is an object" (except private instance variables) paradigm by associating properties and behavior with individual classes, and even primitives such as integer and boolean values (for example, to support different ways of creating instances).
Smalltalk-80 was the first language variant made available outside of PARC, first as Smalltalk-80 Version 1, given to a small number of firms (Hewlett-Packard
Hewlett-Packard
Hewlett-Packard Company or HP is an American multinational information technology corporation headquartered in Palo Alto, California, USA that provides products, technologies, softwares, solutions and services to consumers, small- and medium-sized businesses and large enterprises, including...
, Apple Computer
Apple Computer
Apple Inc. is an American multinational corporation that designs and markets consumer electronics, computer software, and personal computers. The company's best-known hardware products include the Macintosh line of computers, the iPod, the iPhone and the iPad...
, Tektronix
Tektronix
Tektronix, Inc. is an American company best known for its test and measurement equipment such as oscilloscopes, logic analyzers, and video and mobile test protocol equipment. In November 2007, Tektronix became a subsidiary of Danaher Corporation....
, and DEC
Digital Equipment Corporation
Digital Equipment Corporation was a major American company in the computer industry and a leading vendor of computer systems, software and peripherals from the 1960s to the 1990s...
) and universities (UC Berkeley) for "peer review" and implementation on their platforms. Later (in 1983) a general availability implementation, known as Smalltalk-80 Version 2, was released as an image (platform-independent file with object definitions) and a virtual machine
Virtual machine
A virtual machine is a "completely isolated guest operating system installation within a normal host operating system". Modern virtual machines are implemented with either software emulation or hardware virtualization or both together.-VM Definitions:A virtual machine is a software...
specification. ANSI Smalltalk has been the standard language reference since 1998.
Two of the currently popular Smalltalk implementation variants are descendants of those original Smalltalk-80 images. Squeak
Squeak
The Squeak programming language is a Smalltalk implementation. It is object-oriented, class-based and reflective.It was derived directly from Smalltalk-80 by a group at Apple Computer that included some of the original Smalltalk-80 developers...
is an open source
Open source
The term open source describes practices in production and development that promote access to the end product's source materials. Some consider open source a philosophy, others consider it a pragmatic methodology...
implementation derived from Smalltalk-80 Version 1 by way of Apple Smalltalk. VisualWorks
VisualWorks
VisualWorks is a cross-platform implementation of the Smalltalk language. It is implemented as a development system based on "images", which are dynamic collections of software objects, each contained in a system image....
is derived from Smalltalk-80 version 2 by way of Smalltalk-80 2.5 and ObjectWorks (both products of ParcPlace Systems, a Xerox PARC spin-off company formed to bring Smalltalk to the market). As an interesting link between generations, in 2002 Vassili Bykov implemented Hobbes, a virtual machine running Smalltalk-80 inside VisualWorks. (Dan Ingalls later ported Hobbes to Squeak.)
During the late 1980s to mid-1990s, Smalltalk environments — including support, training and add-ons — were sold by two competing organizations: ParcPlace Systems and Digitalk, both California based. ParcPlace Systems tended to focus on the Unix/Sun Microsystems market, while Digitalk focused on Intel-based PCs running Microsoft Windows or IBM's OS/2. Both firms struggled to take Smalltalk mainstream due to Smalltalk's substantial memory needs, limited run-time performance, and initial lack of supported connectivity to SQL
SQL
SQL is a programming language designed for managing data in relational database management systems ....
-based relational database servers. While the high price of ParcPlace Smalltalk limited its market penetration to mid-sized and large commercial organizations, the Digitalk products initially tried to reach a wider audience with a lower price. IBM initially supported the Digitalk product, but then entered the market with a Smalltalk product in 1995 called VisualAge/Smalltalk. Easel introduced Enfin at this time on Windows and OS/2. Enfin became far more popular in Europe, as IBM introduced it into IT shops before their development of IBM Smalltalk (later VisualAge). Enfin was later acquired by Cincom Systems, and is now sold under the name ObjectStudio, and is part of the Cincom Smalltalk product suite.
In 1995, ParcPlace and Digitalk merged into ParcPlace-Digitalk and then rebranded in 1997 as ObjectShare, located in Irvine, CA. ObjectShare (NASDAQ
NASDAQ
The NASDAQ Stock Market, also known as the NASDAQ, is an American stock exchange. "NASDAQ" originally stood for "National Association of Securities Dealers Automated Quotations". It is the second-largest stock exchange by market capitalization in the world, after the New York Stock Exchange. As of...
: OBJS) was traded publicly until 1999, when it was delisted and dissolved. The merged firm never managed to find an effective response to Java as to market positioning, and by 1997 its owners were looking to sell the business. In 1999, Seagull Software acquired the ObjectShare Java development lab (including the original Smalltalk/V and Visual Smalltalk development team), and still owns VisualSmalltalk, although worldwide distribution rights for the Smalltalk product remained with ObjectShare who then sold them to Cincom
Cincom
Cincom Systems is a privately held, multinational, computer technology corporation founded in 1968 by Tom Nies, Tom Richley and Claude Bogardus....
. VisualWorks was sold to Cincom
Cincom
Cincom Systems is a privately held, multinational, computer technology corporation founded in 1968 by Tom Nies, Tom Richley and Claude Bogardus....
and is now part of Cincom Smalltalk. Cincom has backed Smalltalk strongly, releasing multiple new versions of VisualWorks and ObjectStudio each year since 1999.
Cincom
Cincom
Cincom Systems is a privately held, multinational, computer technology corporation founded in 1968 by Tom Nies, Tom Richley and Claude Bogardus....
, Gemstone and Object Arts, plus other vendors continue to sell Smalltalk environments. IBM has 'end of life'd VisualAge Smalltalk having in the late 1990s decided to back Java and it is, , supported by Instantiations, Inc. which has renamed the product VA Smalltalk and released several new versions. The open Squeak
Squeak
The Squeak programming language is a Smalltalk implementation. It is object-oriented, class-based and reflective.It was derived directly from Smalltalk-80 by a group at Apple Computer that included some of the original Smalltalk-80 developers...
implementation has an active community of developers, including many of the original Smalltalk community, and has recently been used to provide the Etoys environment on the OLPC project, a toolkit for developing collaborative applications Croquet Project
Croquet Project
The Croquet Project was an international effort to promote the continued development of the Croquet open source software development kit for creating and delivering deeply collaborative multi-user online applications....
, and the Open Cobalt
Open Cobalt
Open Cobalt is a free and open source software platform for constructing, accessing, and sharing virtual world both on local area networks or across the Internet, without any requirement for centralized servers....
virtual world application. GNU Smalltalk
GNU Smalltalk
GNU Smalltalk is an implementation of the Smalltalk programming language by the GNU Project.The implementation, unlike other Smalltalk environments, uses text files for program input and interprets the contents as Smalltalk code...
is a free software
Free software
Free software, software libre or libre software is software that can be used, studied, and modified without restriction, and which can be copied and redistributed in modified or unmodified form either without restriction, or with restrictions that only ensure that further recipients can also do...
implementation of a derivative of Smalltalk-80 from the GNU
GNU
GNU is a Unix-like computer operating system developed by the GNU project, ultimately aiming to be a "complete Unix-compatible software system"...
project. Last but not least Pharo Smalltalk
Pharo
Pharo is a fork of Squeak, an implementation of the object-oriented, dynamically typed, reflective programming language Smalltalk.Appearing in 2008, Pharo focuses on removing unessential code from Squeak and serves as the reference implementation of Seaside, a web application framework for...
(a fork of Squeak
Squeak
The Squeak programming language is a Smalltalk implementation. It is object-oriented, class-based and reflective.It was derived directly from Smalltalk-80 by a group at Apple Computer that included some of the original Smalltalk-80 developers...
oriented towards research and use in commercial environments) a new and clean MIT licensed open source Smalltalk that brings fresh ideas and interest into the Smalltalk market and scene.
A significant development, that has spread across all current Smalltalk environments, is the increasing usage of two web frameworks, Seaside and AIDA/Web
AIDA/Web
Aida/Web is an object-oriented, open source Smalltalk web application server using the model-view-controller architectural pattern. First developed in 1996 by Janko Mivsek, Aida/Web was designed to integrate the quite distinct object and web philosophies. Viewing the web as essentially a web of...
, to simplify the building of complex web applications. Seaside has seen considerable market interest with Cincom, Gemstone and Instantiations incorporating and extending it.
Influences
John Shoch, a member of the LRG at PARC, acknowledged in his 1979 paper Smalltalk's debt to Plato's theory of forms in which an ideal archetype becomes the template from which other objects are derived.Smalltalk has influenced the wider world of computer programming in four main areas. It inspired the syntax and semantics of other computer programming languages. Secondly, it was a prototype for a model of computation
Model of computation
In computability theory and computational complexity theory, a model of computation is the definition of the set of allowable operations used in computation and their respective costs...
known as message passing
Message passing
Message passing in computer science is a form of communication used in parallel computing, object-oriented programming, and interprocess communication. In this model, processes or objects can send and receive messages to other processes...
. Thirdly, its WIMP
WIMP (computing)
In human–computer interaction, WIMP stands for "windows, icons, menus and pointers", denoting a style of interaction using these elements. It was coined by Merzouga Wilberts in 1980...
GUI
Gui
Gui or guee is a generic term to refer to grilled dishes in Korean cuisine. These most commonly have meat or fish as their primary ingredient, but may in some cases also comprise grilled vegetables or other vegetarian ingredients. The term derives from the verb, "gupda" in Korean, which literally...
inspired the windowing environments of personal computers in the late twentieth and early twenty-first centuries, so much so that the windows of the first Macintosh
Macintosh
The Macintosh , or Mac, is a series of several lines of personal computers designed, developed, and marketed by Apple Inc. The first Macintosh was introduced by Apple's then-chairman Steve Jobs on January 24, 1984; it was the first commercially successful personal computer to feature a mouse and a...
desktop look almost identical to the MVC windows of Smalltalk-80. Finally, the integrated development environment
Integrated development environment
An integrated development environment is a software application that provides comprehensive facilities to computer programmers for software development...
was the model for a generation of visual programming tools that look like Smalltalk's code browsers and debuggers.
Python
Python (programming language)
Python is a general-purpose, high-level programming language whose design philosophy emphasizes code readability. Python claims to "[combine] remarkable power with very clear syntax", and its standard library is large and comprehensive...
and Ruby
Ruby (programming language)
Ruby is a dynamic, reflective, general-purpose object-oriented programming language that combines syntax inspired by Perl with Smalltalk-like features. Ruby originated in Japan during the mid-1990s and was first developed and designed by Yukihiro "Matz" Matsumoto...
have reimplemented some Smalltalk ideas in an environment similar to that of AWK or Perl
Perl
Perl is a high-level, general-purpose, interpreted, dynamic programming language. Perl was originally developed by Larry Wall in 1987 as a general-purpose Unix scripting language to make report processing easier. Since then, it has undergone many changes and revisions and become widely popular...
. The Smalltalk "metamodel" also serves as the inspiration for the object model design of Perl 6
Perl 6
Perl 6 is a major revision to the Perl programming language. It is still in development, as a specification from which several interpreter and compiler implementations are being written. It is introducing elements of many modern and historical languages. Perl 6 is intended to have many...
.
The syntax and runtime behaviour of the Objective-C
Objective-C
Objective-C is a reflective, object-oriented programming language that adds Smalltalk-style messaging to the C programming language.Today, it is used primarily on Apple's Mac OS X and iOS: two environments derived from the OpenStep standard, though not compliant with it...
programming language is strongly influenced by Smalltalk.
There is also a modular Smalltalk-like implementation designed for scripting called S#
Script.NET
Script.NET or S# is a metaprogramming language that provides scripting functionality in Microsoft .NET applications, allowing runtime execution of custom functionality, similar to VBA in Microsoft Office applications. The syntax of Script.NET is similar to JavaScript. It is designed to be simple...
, or Script.NET. S# uses just-in-time compilation
Just-in-time compilation
In computing, just-in-time compilation , also known as dynamic translation, is a method to improve the runtime performance of computer programs. Historically, computer programs had two modes of runtime operation, either interpreted or static compilation...
technology and supports an extended Smalltalk-like language written by David Simmons of Smallscript Corp.
Several programming languages like Self and lately Newspeak
Newspeak (programming language)
Newspeak is a programming language and platform in the tradition of Smalltalk and Self being developed by a team led by Gilad Bracha. The platform includes an IDE, a GUI library, and standard libraries. Starting in 2006, Cadence Design Systems funded its development and employed the main...
have taken the whole idea of Smalltalk in new directions
Object-oriented programming
As in other object-oriented languages, the central concept in Smalltalk-80 (but not in Smalltalk-72) is that of an object. An object is always an instance of a class. Classes are "blueprints" that describe the properties and behavior of their instances. For example, a Window class would declare that windows have properties such as the label, the position and whether the window is visible or not. The class would also declare that instances support operations such as opening, closing, moving and hiding. Each particular Window object would have its own values of those properties, and each of them would be able to perform operations defined by its class.A Smalltalk object can do exactly three things:
- Hold state (references to other objects).
- Receive a message from itself or another object.
- In the course of processing a message, send messages to itself or another object.
The state an object holds is always private to that object. Other objects can query or change that state only by sending requests (messages) to the object to do so. Any message can be sent to any object: when a message is received, the receiver determines whether that message is appropriate. Alan Kay has commented that despite the attention given to objects, messaging is the most important concept in Smalltalk: "The big idea is 'messaging' -- that is what the kernel of Smalltalk/Squeak is all about (and it's something that was never quite completed in our Xerox PARC phase)."
Smalltalk is a "pure" object-oriented programming language, meaning that, unlike Java
Java (programming language)
Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities...
and C++
C++
C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language. It is regarded as an intermediate-level language, as it comprises a combination of both high-level and low-level language features. It was developed by Bjarne Stroustrup starting in 1979 at Bell...
, there is no difference between values which are objects and values which are primitive types. In Smalltalk, primitive values such as integers, booleans and characters are also objects, in the sense that they are instances of corresponding classes, and operations on them are invoked by sending messages. A programmer can change the classes that implement primitive values, so that new behavior can be defined for their instances—for example, to implement new control structures—or even so that their existing behavior will be changed. This fact is summarized in the commonly heard phrase "In Smalltalk everything is an object", which may be more accurately expressed as "all values are objects", as variables are not.
Since all values are objects, classes
Class (computer science)
In object-oriented programming, a class is a construct that is used as a blueprint to create instances of itself – referred to as class instances, class objects, instance objects or simply objects. A class defines constituent members which enable these class instances to have state and behavior...
themselves are also objects. Each class is an instance of the metaclass
Metaclass
In object-oriented programming, a metaclass is a class whose instances are classes. Just as an ordinary class defines the behavior of certain objects, a metaclass defines the behavior of certain classes and their instances. Not all object-oriented programming languages support metaclasses...
of that class. Metaclasses in turn are also objects, and are all instances of a class called Metaclass. Code blocks are also objects.
Reflection
Smalltalk-80 is a totally reflectiveReflection (computer science)
In computer science, reflection is the process by which a computer program can observe and modify its own structure and behavior at runtime....
system, implemented in Smalltalk-80 itself. Smalltalk-80 provides both structural and computational reflection. Smalltalk is a structurally reflective system whose structure is defined by Smalltalk-80 objects. The classes and methods that define the system are themselves objects and fully part of the system that they help define. The Smalltalk compiler compiles textual source code into method objects, typically instances of
CompiledMethod
. These get added to classes by storing them in a class's method dictionary. The part of the class hierarchy that defines classes can add new classes to the system. The system is extended by running Smalltalk-80 code that creates or defines classes and methods. In this way a Smalltalk-80 system is a "living" system, carrying around the ability to extend itself at run time.Since the classes are themselves objects, they can be asked questions such as "what methods do you implement?" or "what fields/slots/instance variables do you define?". So objects can easily be inspected, copied, (de)serialized
Serialization
In computer science, in the context of data storage and transmission, serialization is the process of converting a data structure or object state into a format that can be stored and "resurrected" later in the same or another computer environment...
and so on with generic code that applies to any object in the system.
Smalltalk-80 also provides computational reflection, the ability to observe the computational state of the system. In languages derived from the original Smalltalk-80 the current activation of a method is accessible as an object named via a pseudo-variable (one of the six reserved words),
thisContext
. By sending messages to thisContext
a method activation can ask questions like "who sent this message to me". These facilities make it possible to implement co-routinesCoroutine
Coroutines are computer program components that generalize subroutines to allow multiple entry points for suspending and resuming execution at certain locations...
or Prolog
Prolog
Prolog is a general purpose logic programming language associated with artificial intelligence and computational linguistics.Prolog has its roots in first-order logic, a formal logic, and unlike many other programming languages, Prolog is declarative: the program logic is expressed in terms of...
-like back-tracking without modifying the virtual machine. The exception system is implemented using this facility. One of the more interesting uses of this is in the Seaside web framework which relieves the programmer of dealing with the complexity of a Web Browser's back button by storing continuations for each edited page and switching between them as the user navigates a web site. Programming the web server using Seaside can then be done using a more conventional programming style.
When an object is sent a message that it does not implement, the virtual machine sends the object the
doesNotUnderstand:
message with a reificationReification (computer science)
Reification is the process by which an abstract idea about a computer program is turned into an explicit data model or other object created in a programming language. A computable/addressable object — a resource — is created in a system as a proxy for a non computable/addressable object...
of the message as an argument. The message (another object, an instance of
Message
) contains the selector of the message and an Array
of its arguments. In an interactive Smalltalk system the default implementation of doesNotUnderstand:
is one that opens an error window (a Notifier) reporting the error to the user. Through this and the reflective facilities the user can examine the context in which the error occurred, redefine the offending code, and continue, all within the system, using Smalltalk-80's reflective facilities.Another important use of
doesNotUnderstand:
is intercession. One can create a class that does not define any methods other than doesNotUnderstand:
and does not inheritInheritance (computer science)
In object-oriented programming , inheritance is a way to reuse code of existing objects, establish a subtype from an existing object, or both, depending upon programming language support...
from any other class. The instances of this class effectively understand no messages. So every time a message is sent to these instances they actually get sent
doesNotUnderstand:
, hence they intercede in the message sending process. Such objects are called proxies. By implementing doesNotUnderstand:
appropriately, one can create distributed systems where proxies forward messages across a network to other Smalltalk systems (a facility common in systems like CORBACommon Object Request Broker Architecture
The Common Object Request Broker Architecture is a standard defined by the Object Management Group that enables software components written in multiple computer languages and running on multiple computers to work together .- Overview:CORBA enables separate pieces of software written in different...
, COM+
Component Object Model
Component Object Model is a binary-interface standard for software componentry introduced by Microsoft in 1993. It is used to enable interprocess communication and dynamic object creation in a large range of programming languages...
and RMI
Java remote method invocation
The Java Remote Method Invocation Application Programming Interface , or Java RMI, is a Java application programming interface that performs the object-oriented equivalent of remote procedure calls ....
but first pioneered in Smalltalk-80 in the 1980s), and persistent systems where changes in state are written to a database
Database
A database is an organized collection of data for one or more purposes, usually in digital form. The data are typically organized to model relevant aspects of reality , in a way that supports processes requiring this information...
and the like. An example of this latter is Logic Arts' VOSS (Virtual Object Storage System) available for VA Smalltalk under dual open source
Open source
The term open source describes practices in production and development that promote access to the end product's source materials. Some consider open source a philosophy, others consider it a pragmatic methodology...
and commercial licensing.
Syntax
Smalltalk-80 syntax is rather minimalist, based on only a handful of declarations and reserved words. In fact, only six "keywords" are reserved in Smalltalk:true
, false
, nil
, self
, super
, and thisContext
. These are actually called pseudo-variables, identifiers that follow the rules for variable identifiers but denote bindings that the programmer cannot change. The true
, false
, and nil
pseudo-variables are singletonSingleton pattern
In software engineering, the singleton pattern is a design pattern used to implement the mathematical concept of a singleton, by restricting the instantiation of a class to one object. This is useful when exactly one object is needed to coordinate actions across the system...
instances.
self
and super
refer to the receiver of a message within a method activated in response to that message, but sends to super
are looked up in the superclass of the method's defining class rather than the class of the receiver, which allows methods in subclasses to invoke methods of the same name in superclasses. thisContext
refers to the current activation record. The only built-in language constructs are message sends, assignment, method return and literal syntax for some objects. From its origins as a language for children of all ages, standard Smalltalk syntax uses punctuation in a manner more like English than mainstream coding languages. The remainder of the language, including control structures for conditional evaluation and iteration, is implemented on top of the built-in constructs by the standard Smalltalk class library. (For performance reasons, implementations may recognize and treat as special some of those messages; however, this is only an optimization and is not hardwired into the language syntax.)Literals
The following examples illustrate the most common objects which can be written as literal values in Smalltalk-80 methods.Numbers. The following list illustrates some of the possibilities.
The last two entries are a binary and a hexadecimal number, respectively. The number before the 'r' is the radix
Radix
In mathematical numeral systems, the base or radix for the simplest case is the number of unique digits, including zero, that a positional numeral system uses to represent numbers. For example, for the decimal system the radix is ten, because it uses the ten digits from 0 through 9.In any numeral...
or base. The base does not have to be a power of two; for example 36rSMALLTALK is a valid number equal to 80738163270632 decimal.
Characters are written by preceding them with a dollar sign:
Strings are sequences of characters enclosed in single quotes:
To include a quote in a string, escape it using a second quote:
Double quotes do not need escaping, since single quotes delimit a string:
Two equal strings (strings are equal if they contain all the same characters) can be different objects residing in different places in memory. In addition to strings, Smalltalk has a class of character sequence objects called Symbol. Symbols are guaranteed to be unique—there can be no two equal symbols which are different objects. Because of that, symbols are very cheap to compare and are often used for language artifacts such as message selectors (see below).
Symbols are written as # followed by a string literal. For example:
Selectors are written as # followed by characters. For example:
The ANSI Smalltalk standard permits implementations to, and most implementations do, use the same type for symbols and selectors, and make them equivalent. So in most implementations the above two are equivalent.
Arrays:
defines an array of four integers.
Many implementations support the following literal syntax for ByteArrays:
defines a ByteArray of four integers.
And last but not least, blocks (anonymous function
Anonymous function
In programming language theory, an anonymous function is a function defined, and possibly called, without being bound to an identifier. Anonymous functions are convenient to pass as an argument to a higher-order function and are ubiquitous in languages with first-class functions such as Haskell...
literals)
Blocks are explained in detail further in the text.
Many Smalltalk dialects implement additional syntaxes for other objects, but the ones above are the essentials supported by all.
Variable declarations
The two kinds of variable commonly used in Smalltalk are instance variables and temporary variables. Other variables and related terminology depend on the particular implementation. For example, VisualWorksVisualWorks
VisualWorks is a cross-platform implementation of the Smalltalk language. It is implemented as a development system based on "images", which are dynamic collections of software objects, each contained in a system image....
has class shared variables and namespace shared variables, while Squeak
Squeak
The Squeak programming language is a Smalltalk implementation. It is object-oriented, class-based and reflective.It was derived directly from Smalltalk-80 by a group at Apple Computer that included some of the original Smalltalk-80 developers...
and many other implementations have class variables, pool variables and global variables.
Temporary variable declarations in Smalltalk are variables declared inside a method (see below). They are declared at the top of the method as names separated by spaces and enclosed by vertical bars. For example:
declares a temporary variable named index. Multiple variables may be declared within one set of bars:
declares two variables: index and vowels.
Assignment
A variable is assigned a value via the ':=' syntax. So:Assigns the string 'aeiou' to the previously declared vowels variable. The string is an object (a sequence of characters between single quotes is the syntax for literal strings), created by the compiler at compile time.
In the original Parc Place image, the glyph of the underscore character (_) appeared as a left-facing arrow. Smalltalk originally accepted this left-arrow as the only assignment operator. Some modern code still contains what appear to be underscores acting as assignments, harking back to this original usage. Most modern Smalltalk implementations accept either the underscore or the colon-equals syntax.
Messages
The message is the most fundamental language construct in Smalltalk. Even control structures are implemented as message sends. Smalltalk adopts by default a synchronousAsynchronous method dispatch
Asynchronous method dispatch is a data communication method used when there is a need for the server side to handle a large number of long lasting client requests...
, single dynamic message dispatch
Dynamic dispatch
In computer science, dynamic dispatch is the process of mapping a message to a specific sequence of code at runtime. This is done to support the cases where the appropriate method can't be determined at compile-time...
strategy (as contrasted to a synchronous, multiple dispatch
Multiple dispatch
Multiple dispatch or multimethods or function overloading is the feature of some object-oriented programming languages in which a function or method can be dynamically dispatched based on the run time type of more than one of its arguments...
strategy adopted by some other object-oriented languages).
The following example sends the message 'factorial' to number 42:
In this situation 42 is called the message receiver, while 'factorial' is the message selector. The receiver responds to the message by returning a value (presumably in this case the factorial
Factorial
In mathematics, the factorial of a non-negative integer n, denoted by n!, is the product of all positive integers less than or equal to n...
of 42). Among other things, the result of the message can be assigned to a variable:
"factorial" above is what is called a unary message because only one object, the receiver, is involved. Messages can carry additional objects as arguments, as follows:
In this expression two objects are involved: 2 as the receiver and 4 as the message argument. The message result, or in Smalltalk parlance, the answer is supposed to be 16. Such messages are called keyword messages. A message can have more arguments, using the following syntax:
which answers the index of character 'o' in the receiver string, starting the search from index 6. The selector of this message is "indexOf:startingAt:", consisting of two pieces, or keywords.
Such interleaving of keywords and arguments is meant to improve readability of code, since arguments are explained by their preceding keywords. For example, an expression to create a rectangle using a C++ or Java-like syntax might be written as:
It's unclear which argument is which. By contrast, in Smalltalk, this code would be written as:
The receiver in this case is "Rectangle", a class, and the answer will be a new instance of the class with the specified width and height.
Finally, most of the special (non-alphabetic) characters can be used as what are called binary messages. These allow mathematical and logical operators to be written in their traditional form:
which sends the message "+" to the receiver 3 with 4 passed as the argument (the answer of which will be 7). Similarly,
is the message ">" sent to 3 with argument 4 (the answer of which will be false).
Notice, that the Smalltalk-80 language itself does not imply the meaning of those operators. The outcome of the above is only defined by how the receiver of the message (in this case a Number instance) responds to messages "+" and ">".
A side effect of this mechanism is operator overloading. A message ">" can also be understood by other objects, allowing the use of expressions of the form "a > b" to compare them.
Expressions
An expression can include multiple message sends. In this case expressions are parsed according to a simple order of precedence. Unary messages have the highest precedence, followed by binary messages, followed by keyword messages. For example:is evaluated as follows:
- 3 receives the message "factorial" and answers 6
- 4 receives the message "factorial" and answers 24
- 6 receives the message "+" with 24 as the argument and answers 30
- 30 receives the message "between:and:" with 10 and 100 as arguments and answers true
The answer of the last message sent is the result of the entire expression.
Parentheses can alter the order of evaluation when needed. For example,
will change the meaning so that the expression first computes "3 factorial + 4" yielding 10. That 10 then receives the second "factorial" message, yielding 3628800. 3628800 then receives "between:and:", answering false.
Note that because the meaning of binary messages is not hardwired into Smalltalk-80 syntax, all of them are considered to have equal precedence and are evaluated simply from left to right. Because of this, the meaning of Smalltalk expressions using binary messages can be different from their "traditional" interpretation:
is evaluated as "(3 + 4) * 5", producing 35. To obtain the expected answer of 23, parentheses must be used to explicitly define the order of operations:
Unary messages can be chained by writing them one after another:
which sends "factorial" to 3, then "factorial" to the result (6), then "log" to the result (720), producing the result 2.85733.
A series of expressions can be written as in the following (hypothetical) example, each separated by a period. This example first creates a new instance of class Window, stores it in a variable, and then sends two messages to it.
If a series of messages are sent to the same receiver as in the example above, they can also be written as a cascade with individual messages separated by semicolons:
This rewrite of the earlier example as a single expression avoids the need to store the new window in a temporary variable. According to the usual precedence rules, the unary message "new" is sent first, and then "label:" and "open" are sent to the answer of "new".
Code blocks
A block of code (an anonymous function) can be expressed as a literal value (which is an object, since all values are objects.) This is achieved with square brackets:Where :params is the list of parameters the code can take. This means that the Smalltalk code:
can be understood as:
:
or expressed in lambda terms as:
:
and
can be evaluated as
Or in lambda terms as:
The resulting block object can form a closure
Closure (computer science)
In computer science, a closure is a function together with a referencing environment for the non-local variables of that function. A closure allows a function to access variables outside its typical scope. Such a function is said to be "closed over" its free variables...
: it can access the variables of its enclosing lexical scopes at any time. Blocks are first-class object
First-class object
In programming language design, a first-class citizen , in the context of a particular programming language, is an entity that can be constructed at run-time, passed as a parameter, returned from a subroutine, or assigned into a variable...
s.
Blocks can be executed by sending them the value message (compound variations exist in order to provide parameters to the block e.g. 'value:value:' and 'valueWithArguments:').
The literal representation of blocks was an innovation which on the one hand allowed certain code to be significantly more readable; it allowed algorithms involving iteration to be coded in a clear and concise way. Code that would typically be written with loops in some languages can be written concisely in Smalltalk using blocks, sometimes in a single line. But more importantly blocks allow control structure to be expressed using messages and polymorphism, since blocks defer computation and polymorphism can be used to select alternatives. So if-then-else in Smalltalk is written and implemented as
expr ifTrue: [statements to evaluate if expr] ifFalse: [statements to evaluate if not expr]
True methods for evaluation
ifTrue: trueAlternativeBlock ifFalse: falseAlternativeBlock
^trueAlternativeBlock value
False methods for evaluation
ifTrue: trueAlternativeBlock ifFalse: falseAlternativeBlock
^falseAlternativeBlock value
Note that this is related to functional programming
Functional programming
In computer science, functional programming is a programming paradigm that treats computation as the evaluation of mathematical functions and avoids state and mutable data. It emphasizes the application of functions, in contrast to the imperative programming style, which emphasizes changes in state...
, wherein patterns of computation (here selection) are abstracted
Abstraction (computer science)
In computer science, abstraction is the process by which data and programs are defined with a representation similar to its pictorial meaning as rooted in the more complex realm of human life and language with their higher need of summarization and categorization , while hiding away the...
into higher-order function
Higher-order function
In mathematics and computer science, higher-order functions, functional forms, or functionals are functions which do at least one of the following:*take one or more functions as an input*output a function...
s. For example, the message select: on a Collection is equivalent to the higher-order function filter
Filter (higher-order function)
In functional programming, filter is a higher-order function that processes a data structure in some order to produce a new data structure containing exactly those elements of the original data structure for which a given predicate returns the boolean value true.-Example:In Haskell, the code...
on an appropriate functor
Function object
A function object, also called a functor, functional, or functionoid, is a computer programming construct allowing an object to be invoked or called as though it were an ordinary function, usually with the same syntax.-Description:...
.
Control structures
Control structures do not have special syntax in Smalltalk. They are instead implemented as messages sent to objects. For example, conditional execution is implemented by sending the message ifTrue: to a Boolean object, passing as an argument the block of code to be executed if and only if the Boolean receiver is true.The following code demonstrates this:
Blocks are also used to implement user-defined control structures, enumerators, visitors, pluggable behavior and many other patterns.
For example:
In the last line, the string is sent the message select: with an argument that is a code block literal. The code block literal will be used as a predicate function that should answer true if and only if an element of the String should be included in the Collection of characters that satisfy the test represented by the code block that is the argument to the "select:" message.
A String object responds to the "select:" message by iterating through its members (by sending itself the message "do:"), evaluating the selection block ("aBlock") once with each character it contains as the argument. When evaluated (by being sent the message "value: each"), the selection block (referenced by the parameter "aBlock", and defined by the block literal "[:aCharacter | aCharacter isVowel]"), answers a boolean, which is then sent "ifTrue:". If the boolean is the object true, the character is added to a string to be returned.
Because the "select:" method is defined in the abstract class Collection, it can also be used like this:
Classes
This is a stock class definition:Often, most of this definition will be filled in by the environment. Notice that this is actually a message to the "Object"-class to create a subclass called "MessagePublisher". In other words: classes are first-class object
First-class object
In programming language design, a first-class citizen , in the context of a particular programming language, is an entity that can be constructed at run-time, passed as a parameter, returned from a subroutine, or assigned into a variable...
s in Smalltalk which can receive messages just like any other object and can be created dynamically at execution time.
Methods
When an object receives a message, a method matching the message name is invoked. The following code defines a method publish, and so defines what will happen when this object receives the 'publish' message.The following method demonstrates receiving multiple arguments and returning a value:
The method's name is
#quadMultiply:and:
. The return value is specified with the ^
operator.Note that objects are responsible for determining dynamically at runtime which method to execute in response to a message—while in many languages this may be (sometimes, or even always) determined statically at compile time.
Instantiating classes
The following code:creates (and returns) a new instance of the MessagePublisher class. This is typically assigned to a variable:
However, it is also possible to send a message to a temporary, anonymous object:
Hello World example
In the following code, the message "show:" is sent to the object "Transcript" with the String literal 'Hello, world!' as its argument. Invocation of the "show:" method causes the characters of its argument (the String literal 'Hello, world!') to be displayed in the transcript ("terminal") window.Note that a Transcript window would need to be open in order to see the results of this example.
Image-based persistence
Most popular programming systems separate program code (in the form of class definitions, functions or procedures) from program state (such as objects or other forms of program data). They load program code when a program starts, and any prior program state must be recreated explicitly from configuration files or other data sources. Any settings the program (and programmer) does not explicitly save must be set up again for each restart. A traditional program also loses much useful document information each time a program saves a file, quits, and reloads. This loses details such as undo history or cursor position. Image based systems don't force losing all that just because a computer is turned off, or an OS updates.Many Smalltalk systems, however, do not differentiate between program data (objects) and code (classes). In fact, classes are objects themselves. Therefore most Smalltalk systems store the entire program state (including both Class and non-Class objects) in an image
System image
A system image in computing is a copy of the entire state of a computer system stored in some non-volatile form such as a file. A system is said to be capable of using system images if it can be shut down and later restored to exactly the same state...
file. The image can then be loaded by the Smalltalk virtual machine
Virtual machine
A virtual machine is a "completely isolated guest operating system installation within a normal host operating system". Modern virtual machines are implemented with either software emulation or hardware virtualization or both together.-VM Definitions:A virtual machine is a software...
to restore a Smalltalk-like system to a prior state. This was inspired by FLEX, a language created by Alan Kay
Alan Kay
Alan Curtis Kay is an American computer scientist, known for his early pioneering work on object-oriented programming and windowing graphical user interface design, and for coining the phrase, "The best way to predict the future is to invent it."He is the president of the Viewpoints Research...
and described in his M.Sc. thesis.
Other languages that model application code as a form of data, such as Lisp, often use image-based persistence as well.
Smalltalk images are similar to (restartable) core dump
Core dump
In computing, a core dump consists of the recorded state of the working memory of a computer program at a specific time, generally when the program has terminated abnormally...
s and can provide the same functionality as core dumps, such as delayed or remote debugging with full access to the program state at the time of error.
Level of access
Everything in Smalltalk-80 is available for modification from within a running program. This means that, for example, the IDEIntegrated development environment
An integrated development environment is a software application that provides comprehensive facilities to computer programmers for software development...
can be changed in a running system without restarting it. In some implementations, the syntax of the language or the garbage collection
Garbage collection (computer science)
In computer science, garbage collection is a form of automatic memory management. The garbage collector, or just collector, attempts to reclaim garbage, or memory occupied by objects that are no longer in use by the program...
implementation can also be changed on the fly
On the fly
-Colloquial usage:In colloquial use, on the fly means something created when needed. The phrase is used to mean:# something that was not planned ahead# changes that are made during the execution of same activity: ex tempore, impromptu.-Automotive usage:...
. Even the statement
true become: false
is valid in Smalltalk, although executing it is not recommended. When used judiciously, this level of flexibility allows for one of the shortest required times for new code to enter a production system.Just-in-time compilation
Smalltalk programs are usually compiled to bytecodeBytecode
Bytecode, also known as p-code , is a term which has been used to denote various forms of instruction sets designed for efficient execution by a software interpreter as well as being suitable for further compilation into machine code...
, which is then interpreted by a virtual machine
Virtual machine
A virtual machine is a "completely isolated guest operating system installation within a normal host operating system". Modern virtual machines are implemented with either software emulation or hardware virtualization or both together.-VM Definitions:A virtual machine is a software...
or dynamically translated into machine-native code.
List of implementations
- AthenaAthenaIn Greek mythology, Athena, Athenê, or Athene , also referred to as Pallas Athena/Athene , is the goddess of wisdom, courage, inspiration, civilization, warfare, strength, strategy, the arts, crafts, justice, and skill. Minerva, Athena's Roman incarnation, embodies similar attributes. Athena is...
, Smalltalk scripting engine for Java >=1.6 - Bistro
- CincomCincomCincom Systems is a privately held, multinational, computer technology corporation founded in 1968 by Tom Nies, Tom Richley and Claude Bogardus....
has the following Smalltalk products: ObjectStudio, VisualWorksVisualWorksVisualWorks is a cross-platform implementation of the Smalltalk language. It is implemented as a development system based on "images", which are dynamic collections of software objects, each contained in a system image....
and WebVelocity.- Visual Smalltalk EnterpriseVisual Smalltalk EnterpriseVisual Smalltalk Enterprise is a Smalltalk dialect that runs only on Microsoft Windows, and is the last in a long line of Smalltalk implementations first produced by Digitalk and now available through Cincom....
, and family, including Smalltalk/V
- Visual Smalltalk Enterprise
- Exept Software, Smalltalk/X
- F-ScriptF-Script programming languageF-Script is an object-oriented scripting programming language for Apple_Inc Mac OS X operating system developed by Philippe Mougin. F-Script is tagged as Cocoa developer's best friend, wherein the package provides an integrated set of tools that makes it possible to interactively explore and...
- Gemstone, GemStone/SDatabase management systemA database management system is a software package with computer programs that control the creation, maintenance, and use of a database. It allows organizations to conveniently develop databases for various applications by database administrators and other specialists. A database is an integrated...
- GNU SmalltalkGNU SmalltalkGNU Smalltalk is an implementation of the Smalltalk programming language by the GNU Project.The implementation, unlike other Smalltalk environments, uses text files for program input and interprets the contents as Smalltalk code...
- Étoilé Pragmatic Smalltalk, Smalltalk for Étoilé, a GNUstep-based user environment
- StepTalkStepTalkStepTalk is the official GNUstep scripting framework that represents separate scriptable servers or applications as a single object environment...
, GNUstep scripting framework uses Smalltalk language on an Objective-CObjective-CObjective-C is a reflective, object-oriented programming language that adds Smalltalk-style messaging to the C programming language.Today, it is used primarily on Apple's Mac OS X and iOS: two environments derived from the OpenStep standard, though not compliant with it...
runtime
- Little SmalltalkLittle SmalltalkLittle Smalltalk is a non-standard dialect of the Smalltalk programming language invented by Timothy Budd. It was originally described in the book: "A Little Smalltalk", Timothy Budd, Addison-Wesley, 1987, ISBN 0-201-10698-1....
- Object Arts, Dolphin SmalltalkDolphin SmalltalkDolphin Smalltalk, or "Dolphin" for short , is an implementation of the Smalltalk programming language by Object Arts, targeted at the Microsoft Windows platform.The last major release was Dolphin Smalltalk X6, which comes in two versions:...
- LSW Vision-Smalltalk have partnered with Object Arts
- Panda Smalltalk, open source engine, written in C, has no dependencies except libc
- Pharo SmalltalkPharoPharo is a fork of Squeak, an implementation of the object-oriented, dynamically typed, reflective programming language Smalltalk.Appearing in 2008, Pharo focuses on removing unessential code from Squeak and serves as the reference implementation of Seaside, a web application framework for...
, Pharo Project's open-source multi-platform Smalltalk - Pocket SmalltalkPocket SmalltalkPocket Smalltalk is a Smalltalk environment that runs in Microsoft Windows and cross-compiles on the Palm Pilot platform.The resulting executables are usable on the Palm 3.5 platform and up....
, runs on Palm Pilot - Refactory, produces #Smalltalk
- Object Connect, Smalltalk MTSmalltalk MTSmalltalk MT is an implementation of the Smalltalk programming language created in 1994 by Tarik Kerroum to deal with some of the shortcomings of Smalltalk-80 style of implementations...
Smalltalk for Windows - Smalltalk YXSmalltalk YXSmalltalk YX is an open source programming language. It's an implementation of the Smalltalk-80 standard.Syx is written in the C programming language and has the following purposes:* Readable code* Flexibility through easy creation of plugins...
- SqueakSqueakThe Squeak programming language is a Smalltalk implementation. It is object-oriented, class-based and reflective.It was derived directly from Smalltalk-80 by a group at Apple Computer that included some of the original Smalltalk-80 developers...
, open source Smalltalk- Cog, JITJust-in-time compilationIn computing, just-in-time compilation , also known as dynamic translation, is a method to improve the runtime performance of computer programs. Historically, computer programs had two modes of runtime operation, either interpreted or static compilation...
VM written in Squeak Smalltalk- CogDroid, port of non-JIT variant of Cog VM to Android
- eToysEToys (Programming Language)Etoys is a child-friendly computer environment and object-oriented prototype-based programming language for use in education.Etoys is a media-rich authoring environment with a scripted object model for many different objects that runs on different platforms and is free and open source.- Brief...
, eToys visual programming system for learning - iSqueak, Squeak interpreter port for iOS devices, iPhone/iPad
- JSqueak, Squeak interpreter written in Java
- PotatoPotatoThe potato is a starchy, tuberous crop from the perennial Solanum tuberosum of the Solanaceae family . The word potato may refer to the plant itself as well as the edible tuber. In the region of the Andes, there are some other closely related cultivated potato species...
, Squeak interpreter written in Java, a direct derivative of JSqueak
- Potato
- RoarVM, RoarVM is a multi- and manycore interpreter for Squeak and Pharo
- Cog, JIT
- StrongtalkStrongtalkStrongtalk is a Smalltalk environment with optional static typing support. Strongtalk can make some compile time checks, and offer "stronger" type-safety guarantees; this is the source of its name...
, for Windows, offers optional strong typing - Susie, Scripting Using a Smalltalk Interpreter Engine
- Instantiations, VA Smalltalk being the follow-on to IBM VisualAge Smalltalk
- VisualAge Smalltalk
- Amber SmalltalkAmber SmalltalkAmber Smalltalk, formerly known as Jtalk, is an implementation of the Smalltalk-80 language that runs on the JavaScript runtime of a web browser. It is designed to enable client-side development using the Smalltalk programming language....
Smalltalk running atop JavaScriptJavaScriptJavaScript is a prototype-based scripting language that is dynamic, weakly typed and has first-class functions. It is a multi-paradigm language, supporting object-oriented, imperative, and functional programming styles....
External links
- The World of Smalltalk, Smalltalk books and videos, implementations, frameworks and tools, blogs and mailing lists
- Planet Smalltalk, an aggregator of Smalltalk blog posts
- Downloadable books on Smalltalk, permission obtained to make these books freely available, over 25 full texts scanned from print
- ESUG (European Smalltalk Users Group), non-profit organization with commercial and academic members, has various promotion activities including a yearly event since 1993
- STIC (Smalltalk Industry Council), promoting Smalltalk on behalf of the Smalltalk community
- La Fundacion Argentina de Smalltalk (FAST), Organizer of annual Smalltalk conference in Argentina
- ClubSmalltalk, a Latin American group with a website in English to promote the Smalltalk technology
- Smalltalk.org, advocacy site