FACTOID # 161: The United States, India and China account for a third of all arable and permanent cropland in the world.
 
 Home   Encyclopedia   Statistics   Countries A-Z   Flags   Maps   Education   Forum   FAQ   About 
 
WHAT'S NEW
RELATED ARTICLES
People who viewed "Smalltalk" also viewed:
RECENT ARTICLES
More Recent Articles »
 

SEARCH ALL

FACTS & STATISTICS   

Search encyclopedia, statistics and forums:

 

 

(* = Graphable)

 

 


Encyclopedia > Smalltalk

Smalltalk
Paradigm: object-oriented
Appeared in: Development started in 1969
Publicly available in 1980
Designed by: Alan Kay, Dan Ingalls, Adele Goldberg
Developer: Alan Kay, Dan Ingalls, Adele Goldberg, Ted Kaehler, Scott Wallace, and Xerox PARC
Typing discipline: dynamic
Major implementations: Squeak, VisualWorks
Influenced by: Lisp, Logo; Sketchpad, Simula
Influenced: ObjC, Self, Java, Dylan, AppleScript, NewtonScript, Python, Ruby

Smalltalk is an object-oriented, dynamically typed, reflective programming language. A programming paradigm is a paradigmatic style of programming (compare with a methodology, which is a paradigmatic style of doing software engineering). ... Object-oriented programming (OOP) is a programming paradigm that uses objects to design applications and computer programs. ... For the Stargate SG-1 episode, see 1969 (Stargate SG-1). ... Year 1980 (MCMLXXX) was a leap year starting on Tuesday (link displays the 1980 Gregorian calendar). ... Alan Curtis Kay (born May 17, 1940) is an American computer scientist, known for his early pioneering work on object-oriented programming and windowing graphical user interface design. ... Dan Ingalls is one of the creators of Smalltalk. ... Dr. Adele Goldberg is a computer scientist who wrote or co-wrote books on the programming language Smalltalk-80. ... A software developer is a person who is concerned with one or more facets of the software development process, a somewhat broader scope of computer programming or a specialty of project managing. ... PARC current logo. ... In computer science, a type system defines how a programming language classifies values and expressions into types, how it can manipulate those types and how they interact. ... In computer science, a type system defines how a programming language classifies values and expressions into types, how it can manipulate those types and how they interact. ... Look up Implementation in Wiktionary, the free dictionary. ... The Squeak programming language is a Smalltalk implementation, derived directly from Smalltalk-80, by Smalltalks originators during their time at Apple Computer and later, at Walt Disney Imagineering, where it was intended for use in internal Disney projects such as a Mickey Mouse PDA. It is object-oriented, and... VisualWorks is one of the leading implementations of the Smalltalk programming language and environment. ... Lisp is a family of computer programming languages with a long history and a distinctive fully-parenthesized syntax. ... The Logo programming language is a functional programming language. ... Sketchpad was a revolutionary computer program written by Ivan Sutherland in 1963 in the course of his PhD thesis. ... 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. ... Objective-C, often referred to as ObjC or more seldomly as Objective C or Obj-C, is an object oriented programming language implemented as an extension to C. It is used primarily on Mac OS X and GNUstep, two environments based on the OpenStep standard, and is the primary language... This does not adequately cite its references or sources. ... Java is a programming language originally developed by Sun Microsystems and released in 1995. ... The Dylan programming language (pronounced , like the name) is functional, object-oriented, reflective and dynamic. ... AppleScript is a scripting language devised by Apple, Inc. ... NewtonScript is a prototype based programming language created to write programs for the Apple Newton. ... Python is a high-level programming language first released by Guido van Rossum in 1991. ... Ruby is a reflective, dynamic, object-oriented programming language. ... Small talk may mean: The act of making conversation for the sake of conversation. ... Object-oriented programming (OOP) is a programming paradigm that uses objects to design applications and computer programs. ... In computer science, a type system defines how a programming language classifies values and expressions into types, how it can manipulate those types and how they interact. ... In computer science, reflection is the process by which a computer program of the appropriate type can be modified in the process of being executed, in a manner that depends on abstract features of its code and its runtime behavior. ... Computer programming (often shortened to programming or coding) is the process of writing, testing, and maintaining the source code of computer programs. ...

A Smalltalk program is a description of a dynamic computational process. The Smalltalk programming language is a notation for defining such programs. From ANSI Smalltalk standard, section 3.

Smalltalk was created as the language to underpin the "new world" of computing exemplified by "human-computer symbiosis" [1].

… one would compute with a handheld "Dynabook" in a way that would not be possible on a shared mainframe; millions of potential users meant that the user interface would have to become a learning environment along the lines of Montessori and Bruner; and needs for large scope, reduction in complexity, and end-user literacy would require that data and control structures be done away with in favor of a more biological scheme of protected universal cells interacting only through messages that could mimic any desired behavior. Early Smalltalk was the first complete realization of these new points of view as parented by its many predecessors in hardware, language and user interface design. It became the exemplar of the new computing, in part, because we were actually trying for a qualitative shift in belief structures—a new Kuhnian paradigm in the same spirit as the invention of the printing press—and thus took highly extreme positions which almost forced these new styles to be invented.[2] Thomas Samuel Kuhn (pronounced )(July 18, 1922 – June 17, 1996) was an American intellectual who wrote extensively on the history of science and developed several important notions in the philosophy of science. ...

Smalltalk was designed and created in part for educational use, more so for Constructivist teaching, at Xerox PARC by Alan Kay, Dan Ingalls, Adele Goldberg, Ted Kaehler, Scott Wallace, and others during the 1970s, influenced by Lisp and Logo, Sketchpad and Simula. Constructivism is a set of assumptions about the nature of human learning that guide constructivist learning theories and teaching methods of education. ... In education, teachers are those who teach students or pupils, often a course of study or a practical skill. ... PARC current logo. ... Alan Curtis Kay (born May 17, 1940) is an American computer scientist, known for his early pioneering work on object-oriented programming and windowing graphical user interface design. ... Dan Ingalls is one of the creators of Smalltalk. ... Dr. Adele Goldberg is a computer scientist who wrote or co-wrote books on the programming language Smalltalk-80. ... The 1970s decade refers to the years from 1970 to 1979, also called The Seventies. ... Lisp is a family of computer programming languages with a long history and a distinctive fully-parenthesized syntax. ... The Logo programming language is a functional programming language. ... Sketchpad was a revolutionary computer program written by Ivan Sutherland in 1963 in the course of his PhD thesis. ... 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. ...


The language was first generally released as Smalltalk-80 and has been widely used since. 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.

Contents

History

There are a large number of Smalltalk versions and variants, as there are with all computer languages. The unqualified word Smalltalk is often used to indicate the original Smalltalk-80 language.


Smalltalk was the product of research by a group of researchers led by Alan Kay[3] 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 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. Alan Curtis Kay (born May 17, 1940) is an American computer scientist, known for his early pioneering work on object-oriented programming and windowing graphical user interface design. ... Xerox Palo Alto Research Center (PARC) was a flagship research division of the Xerox Corporation, based in Palo Alto, California, USA. It was founded in 1970 and spun out as a separate company in 2002. ... Dan Ingalls is one of the creators of Smalltalk. ... In computer science, message passing is a form of communication used in concurrent programming, parallel programming, object-oriented programming, and interprocess communication. ... 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. ... 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 determine how to respond to... 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 determine how to respond to...


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 tools now familiar including a class library code browser/editor. 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. ... An integrated development environment (IDE) (also known as an integrated design environment and integrated debugging environment) is computer software to help computer programmers develop software. ...


Smalltalk-80 added metaclasses, to help maintain the "everything is an object" (except 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). In object-oriented programming, a metaclass is a class whose instances are classes. ...


Smalltalk-80 was the first language made available outside of PARC, first as Smalltalk-80 Version 1, given to a small number of companies (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. The Hewlett-Packard Company (NYSE: HPQ), commonly known as HP, is a very large, global company headquartered in Palo Alto, California, United States. ... Apple Inc. ... Tektronix is a United States corporation that is currently a major presence in the test, measurement, and measuring industry. ... The DEC logo Digital Equipment Corporation was a pioneering American company in the computer industry. ... The University of California, Berkeley (also known as Cal, UC Berkeley, UCB, or simply Berkeley) is a prestigious, public, coeducational university situated in the foothills of Berkeley, California to the east of San Francisco Bay, overlooking the Golden Gate and its bridge. ... In computer science, a virtual machine is software that creates a virtualized environment between the computer platform and its operating system, so that the end user can operate software on an abstract machine. ...


Two of the currently popular Smalltalk languages 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). The Squeak programming language is a Smalltalk implementation, derived directly from Smalltalk-80, by Smalltalks originators during their time at Apple Computer and later, at Walt Disney Imagineering, where it was intended for use in internal Disney projects such as a Mickey Mouse PDA. It is object-oriented, and... Open source refers to projects that are open to the public and which draw on other projects that are freely available to the general public. ... VisualWorks is one of the leading implementations of the Smalltalk programming language and environment. ... Dan Ingalls is one of the creators of Smalltalk. ...


During the 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 emphasized Intel-based PCs that were running either Microsoft Windows or IBM's OS/2. Both companies, however, struggled with commercial success due to Smalltalk's substantial memory footprint, limited run-time performance, visibility of source code in distributed applications, and lack of supported connectivity to SQL-based relational database servers. SQL (IPA: or IPA: ), commonly expanded as Structured Query Language, is a computer language designed for the retrieval and management of data in relational database management systems, database schema creation and modification, and database object access control management. ...


In 1995, as Smalltalk was declining commercially, the two organizations merged and were rebranded ObjectShare, located in Irvine, CA. ObjectShare (NASDAQ: OBJS) was traded publicly until 1999, when it was delisted and dissolved. The stronger version (VisualWorks) was sold to and is now part of Cincom Smalltalk, from Cincom. NASDAQ in Times Square, New York City. ... Cincom Systems is a company founded in 1968, making it one of the longest-serving companies in the software industry. ...


ANSI Smalltalk is the standard language reference since 1998.


IBM has indicated that VisualAge Smalltalk will be supported by partner company (and VisualAge implementors) Instantiations. Cincom, Object Arts, GemStone, and other vendors continue to sell Smalltalk environments. The open Squeak implementation has a relatively active community of developers, including many of the original Smalltalk community. GNU Smalltalk is a free software implementation of a derivative of Smalltalk-80 from the GNU project. There is even a Smalltalk-80 like cross-compiler [4] for the PalmPilot which runs on Windows (though it seems that development may have stagnated in recent years). The Squeak programming language is a Smalltalk implementation, derived directly from Smalltalk-80, by Smalltalks originators during their time at Apple Computer and later, at Walt Disney Imagineering, where it was intended for use in internal Disney projects such as a Mickey Mouse PDA. It is object-oriented, and... GNU Smalltalk is an implementation of the Smalltalk programming language by the GNU Project. ... Clockwise from top: The logo of the GNU Project (the GNU head), the Linux kernel mascot Tux the Penguin, and the FreeBSD daemon Free software is a term coined by Richard Stallman and the Free Software Foundation[1] to refer to software that can be used, studied, and modified without... GNU (pronounced ) is a computer operating system composed entirely of free software. ... A cross compiler is a compiler capable of creating executable code for a platform other than the one on which the cross compiler is run. ...


There is also a high-performance JITted modular Smalltalk-like implementation designed for scripting called S# (S-Sharp) which supports an extended Smalltalk-like language written by David Simmons of Smallscript Corp. In computing, just-in-time compilation (JIT), also known as dynamic translation, is a technique for improving the performance of bytecode-compiled programming systems, by translating bytecode into native machine code at runtime. ...


More recently, Python and Ruby have reimplemented some Smalltalk ideas with more C/Java-like syntax. (From its origins as a teaching language, standard Smalltalk syntax uses punctuation in a manner more like English than mainstream coding languages.) Python is a high-level programming language first released by Guido van Rossum in 1991. ... Ruby is a reflective, object-oriented programming language. ... C is a general-purpose, block structured, procedural, imperative computer programming language developed in 1972 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system. ... Java is a programming language originally developed by Sun Microsystems and released in 1995. ...


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. Object-oriented programming (OOP) is a programming paradigm that uses objects to design applications and computer programs. ...


A Smalltalk object can do exactly three things:

  1. Hold state (references to other objects).
  2. Receive a message from itself or another object.
  3. 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.)


Smalltalk is a 'pure' OO 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 summarised in the commonly heard phrase "In Smalltalk everything is an object" (which would more accurately be expressed as "all values are objects", as variables aren't). Java is a programming language originally developed by Sun Microsystems and released in 1995. ... C++ (pronounced see plus plus, IPA: ) is a general-purpose, programming language with high-level and low-level capabilities. ...


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. In object-oriented programming, a class is a programming language construct that is used to group related instance variables and methods. ... In object-oriented programming, a metaclass is a class whose instances are classes. ...


Reflection

Smalltalk-80 is a fully reflective 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 redefines classes and methods. In this way a Smalltalk-80 system is a "living" system, carrying around the ability to extend itself at run-time. In computer science, reflection is the process by which a computer program of the appropriate type can be modified in the process of being executed, in a manner that depends on abstract features of its code and its runtime behavior. ...


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. In computer science, in the context of data storage and transmission, serialization is the process of saving an object onto a storage medium (such as a file, or a memory buffer) or to transmit it across a network connection link, either in binary form, or in some human-readable text...


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 keyword, 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-routines or Prolog-like back-tracking without modifying the virtual machine. One of the more interesting uses of this is in Avi Bryant's 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. In computer science, coroutines are program components that generalize subroutines to allow multiple entry points and suspending and resuming of execution at certain locations. ... Prolog is a logic programming language. ... Seaside is an open source web application framework for developing web applications in Smalltalk. ...


When an object is sent a message that it does not implement, the virtual machine sends the object the doesNotUnderstand: message with a reification 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 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. Reification, in the context of object-oriented programming, is the implementation of an abstract behavior. ...


Yet another important use of doesNotUnderstand: is intercession. One can create a class that does not define any methods other than doesNotUnderstand: and does not inherit 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 CORBA and RMI but first pioneered in Smalltalk-80 in the 1980s), persistent systems where changes in state are written to a database and the like. The Common Object Request Broker Architecture (CORBA) is a standard defined by the Object Management Group (OMG) that enables software components written in multiple computer languages and running on multiple computers to work together. ... A typical implementation model of Java-RMI using Stub and Skeleton objects. ... This article does not cite any references or sources. ...


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 not actually keywords, they are singleton instances. Smalltalk does not define any keywords.) The only built-in language constructs are message sends, assignment, method return and literal syntax for some objects. The remainder of the language, including control structures for conditional evaluation and iteration, is implemented on top of those 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, not hardwired into the language syntax). In software engineering, the singleton pattern is a design pattern that is used to restrict instantiation of a class to one object. ...


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

 42 -42 123.45 1.2345e2 2r10010010 16rA000 

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 (for the curious, equal to 80738163270632 decimal). The radix (Latin for root), also called base, is the number of various unique symbols (or digits or numerals) a positional numeral system uses to represent numbers. ...


Characters are written by preceding them with a dollar sign:

 $A 

Strings are sequences of characters enclosed in single quotes:

 'Hello, world!' 

To include a quote in a string, escape it using a second quote:

 'I said, ''Hello, world!'' to them.' 

Double quotes do not need escaping, since single quotes delimit a string:

 'I said, "Hello, world!" to them.' 

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 characters. For example:

 #foo 

Arrays:

 #(1 2 3 4) 

defines an array of four integers.


And last but not least, blocks (anonymous function literals)

 [... Some smalltalk code...] 

Blocks are explained in detail further in the text.


Many Smalltalk dialects implement additional syntaxes for other objects, but the ones above are the bread and butter 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, VisualWorks has class shared variables and namespace shared variables, while Squeak and many other implementations have class variables, pool variables and global variables. VisualWorks is one of the leading implementations of the Smalltalk programming language and environment. ... The Squeak programming language is a Smalltalk implementation, derived directly from Smalltalk-80, by Smalltalks originators during their time at Apple Computer and later, at Walt Disney Imagineering, where it was intended for use in internal Disney projects such as a Mickey Mouse PDA. It is object-oriented, and...


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:

 | index | 

declares a temporary variable named index. Multiple variables may be declared within one set of bars:

 | index vowels | 

declares two variables: index and vowels.


Assignment

A variable is assigned a value via the ':=' syntax. So:

 vowels := 'aeiou' 

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.


Messages

A message is the most fundamental language construct in Smalltalk. Even control structures are implemented as message sends. The following examples sends the message 'factorial' to number 42.

 42 factorial 

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 a factorial of 42). Among other things, the result of the message can be assigned to a variable:

 aRatherBigNumber := 42 factorial 

"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:

 2 raisedTo: 4 

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:

 'hello world' indexOf: $o startingAt: 6 

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 greatly improves 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:

 new Rectangle(100, 200); 

It's unclear which argument is which—is the argument order (width, height) or (height, width)? In Java, you have to look up the API online to find out that the class's argument-order is, in fact, (width, height). By contrast, in Smalltalk, this code would be written unambiguously as:

 Rectangle width: 100 height: 200 

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:

 3 + 4 

which sends the message "+" to the receiver 3 with 4 passed as the argument (the answer of which will be 7). Similarly,

 3 > 4 

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:

 3 factorial + 4 factorial between: 10 and: 100 

is evaluated as follows:

  1. 3 receives the message "factorial" and answers 6
  2. 4 receives the message "factorial" and answers 24
  3. 6 receives the message "+" with 24 as the argument and answers 30
  4. 30 receives the message "between:and:" with 10 and 100 as arguments and answers true

The answer of the last message send is the result of the entire expression.


Parentheses can alter the order of evaluation when needed. For example,

 (3 factorial + 4) factorial between: 10 and: 100 

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:

 3 + 4 * 5 

is evaluated as "(3 + 4) * 5", producing 35.


Unary messages can be chained by writing them one after another:

 3 factorial factorial log 

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 ending with a period. This example first creates a new instance of class Window, stores it in a variable, and then sends two messages to it.

 | window | window := Window new. window label: 'Hello'. window open. 

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:

 (Window new) label: 'Hello'; open 

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:

 [ :params | <message-expressions> ] 

Where :params is the list of parameters the code can take. This means that the Smalltalk code:

 [:x | x + 1] 

can be understood as:

 f(x) = x + 1 

(or, expressed using lambda calculus): The lambda calculus is a formal system designed to investigate function definition, function application, and recursion. ...

 λx.(x+1) 

and

 f(3) = 3 + 1 

can be evaluated as

 [:x | x + 1] value: 3 

The resulting block object is a closure. It can (at any time) access the variables of its enclosing lexical scopes. Blocks are first class objects. That is, references to blocks can be passed as arguments, returned as values, or stored as a state, just like any other objects. Blocks can be asked to execute their code by sending them a "value"-message (with one argument for each parameter in the block). In programming languages, a closure is a function that refers to free variables in its lexical context. ...


The literal representation of blocks was an innovation which 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.

 positiveAmounts := allAmounts select: [:amt | amt isPositive] 

Note that this is related to functional programming, wherein patterns of computation (here selection) are abstracted into higher-order functions. For example, the message select: on a Collection is equivalent to the higher-order function filter on an appropriate functor. Functional programming is a programming paradigm that conceives computation as the evaluation of mathematical functions and avoids state and mutable data. ... In mathematics and computer science, higher-order functions are functions which can take other functions as arguments, and may also return functions as results. ...


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:

 result := a > b ifTrue:[ 'greater' ] ifFalse:[ 'less' ] 

Blocks are also used to implement user-defined control structures, enumerators, visitors, pluggable behavior and many other patterns. For example:

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

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:

 | 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]. 

Classes

This is a stock class definition:

 Object subclass: #MessagePublisher instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Smalltalk Examples' 

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 objects in Smalltalk which can receive messages just like any other object and can be created dynamically at execution time. In computing, a first-class object (also -value, -entity, -citizen), in the context of a particular programming language, is an entity which can be used in programs without restriction (when compared to other kinds of objects in the same language). ...


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.

 publish Transcript show: 'Hello, World!' 

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:

 MessagePublisher new 

creates (and returns) a new instance of the MessagePublisher class. This is typically assigned to a variable:

 publisher := MessagePublisher new 

However, it is also possible to send a message to a temporary, anonymous object:

 MessagePublisher new publish 

Hello World example

Main article: Hello world program

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 ("console") window. A hello world program is a software program that prints out Hello, World! on a display device. ...

 Transcript show: 'Hello, world!'. 

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 application data). They load the program code when an application is started, and any previous application state has to be recreated explicitly from configuration files or other data sources. Any settings the application programmer doesn't explicitly save, you have to set back up whenever you restart. A traditional application also throws away a lot of useful document information every time you save a file, quit and reload. You lose details such as undo history or cursor position. Image based systems don't force you to scrap all that just because you need to turn off your computer, or update the OS.


Many Smalltalk systems, however, do not differentiate between application data (objects) and code (classes). In fact, classes are objects themselves. Therefore most Smalltalk systems store the entire application state (including both Class and non-Class objects) in an image file. The image can then be loaded by the Smalltalk interpreter to restore a Smalltalk-like system to a previous state. In computing a system image is the state of a computer or software system stored in some form. ...


Other languages that model application code as a form of data, such as Lisp, often use image-based persistence as well. Lisp is a family of computer programming languages with a long history and a distinctive fully-parenthesized syntax. ...


Smalltalk images are similar to (restartable) core dumps and can provide the same functionality as core dumps, such as delayed or remote debugging with full access to the application state at the time of error. A core dump is the recorded state of the working memory of a computer program at a specific time, generally when the program has terminated abnormally (crashed). ...


Level of access

Everything in Smalltalk-80 is available for modification from within a running program. This means that, for example, the IDE 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 true become: false is valid in Smalltalk, although executing it is not recommended. This article or section does not cite any references or sources. ... In computer science, garbage collection (also known as GC) is a form of automatic memory management. ... In relation to computer technology, on the fly describes activities that develop or occur dynamically rather than as the result of something that is statically predefined. ...


Just-in-time compilation

Smalltalk programs are usually compiled to bytecode, which is then interpreted by a virtual machine or dynamically translated into machine-native code. This mechanism has been adopted by languages such as Java and C#. In computing, just-in-time compilation (JIT), also known as dynamic translation, is a technique for improving the performance of bytecode-compiled programming systems, by translating bytecode into native machine code at runtime. ... Bytecode is a binary representation of an executable program designed to be executed by a virtual machine rather than by dedicated hardware. ... In computer science, a virtual machine is software that creates a virtualized environment between the computer platform and its operating system, so that the end user can operate software on an abstract machine. ... Java is a programming language originally developed by Sun Microsystems and released in 1995. ... The title given to this article is incorrect due to technical limitations. ...


Language variants

Ambrai Smalltalk Ambrai Smalltalk is an implementation of the Smalltalk language and development environment for Mac OS X. External Links http://www. ... The Bistro programming language is object oriented, dynamically typed, and reflective. ... VisualWorks is one of the leading implementations of the Smalltalk programming language and environment. ... F-Script is an object-oriented scripting programming language developed by Philippe Mougin at TechMetrix Research in France. ... GNU Smalltalk is an implementation of the Smalltalk programming language by the GNU Project. ... International Business Machines Corporation (IBM, or colloquially, Big Blue) (NYSE: IBM) (incorporated June 15, 1911, in operation since 1888) is headquartered in Armonk, New York, USA. The company manufactures and sells computer hardware, software, and services. ... VisualAge was the name of a family of computer integrated development environments from IBM, which included support for a few popular (and not so popular) computer Programming_languages. ... Little Smalltalk is a non-standard dialect of the Smalltalk object-oriented programming language invented by Timothy Budd. ... LSW Vision-Smalltalk (LSWVST) is a commercial implementation of the Smalltalk language and development environment for MS-Windows OSes. ... Pocket Smalltalk is an environment that runs in Microsoft Windows and cross-compiles to the Palm Pilot platform. ... Link title Headline text Insert non-formatted text here--203. ... The Squeak programming language is a Smalltalk implementation, derived directly from Smalltalk-80, by Smalltalks originators during their time at Apple Computer and later, at Walt Disney Imagineering, where it was intended for use in internal Disney projects such as a Mickey Mouse PDA. It is object-oriented, and... StepTalk is the official GNUstep scripting framework. ... Objective-C, often referred to as ObjC or more seldomly as Objective C or Obj-C, is an object oriented programming language implemented as an extension to C. It is used primarily on Mac OS X and GNUstep, two environments based on the OpenStep standard, and is the primary language... Strongtalk is a Smalltalk environment, that is strongly type checked, and can make some compile time checks. ... Visual Smalltalk Enterprise (VSE) 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. ... VistaSmalltalk, or Vistascript, is a Microsoft Vista scripting Internet Explorer web development environment based on Smalltalk for the Microsoft . ...

External links

Wikibooks has a book on the topic of

Image File history File links Wikibooks-logo-en. ... Wikibooks logo Wikibooks, previously called Wikimedia Free Textbook Project and Wikimedia-Textbooks, is a wiki for the creation of books. ... Dan Ingalls is one of the creators of Smalltalk. ... In computer science a byte is a unit of measurement of information storage, most often consisting of eight bits. ... Dan Ingalls is one of the creators of Smalltalk. ...

Books


  Results from FactBites:
 
Smalltalk - Wikipedia, the free encyclopedia (3690 words)
Smalltalk is a 'pure' OO language, meaning that unlike Java and C++ there is no difference between objects and primitive types.
Smalltalk images are similar to core dumps and generally provide the same benefits, such as delayed or remote debugging with full access to the application state at the time of error.
Smalltalk programs are usually compiled to bytecode, which is then interpreted by a virtual machine or dynamically translated into machine-native code.
introduction to smalltalk (6779 words)
Smalltalk V and later Visual Smalltalk restricted itself to a much simplified user interface, due largely to hardware constraints on early IBM PCs and Microsoft's DOS operating system, but it was sold for a very reasonable price.Xerox itself reaped only sparse rewards from its investment in the Smalltalk project.
Smalltalk is a "dynamically typed" language in which there is no type information associated with identifiers, but rather with the objects themselves - as reflected in the classes they are instances of and consequently the types of messages they are willing to react to.
Smalltalk's strong object-orientation also permits additional control structures to be defined in an elegant way, attaching appropriate methods to the class of objects which guards the control structures' execution.
  More results at FactBites »

 

COMMENTARY     


Share your thoughts, questions and commentary here
Your name
Your location
Your comments
Please enter the 5-letter protection code