Google
 
   
Login
Username:

Password:


Lost Password?

Register now!
Search
Main Menu
top books
Polls
What do you think about php-deluxe.net?
Excellent!
Cool
Hmm..not bad
What the hell is this?
encyclopedia
recommendation
compare webbrowser
Freenet DSL
Who's Online
6 user(s) are online (6 user(s) are browsing encyclopedia)

Members: 0
Guests: 6

more...
browser tip
Unix Befehle
manual of unix befehle
recommendation!
Sponsored
partner

Smalltalk

Smalltalk is an Object-oriented programming, dynamic typing, Reflection (computer science), programming language designed at Xerox PARC by Alan Kay, Dan Ingalls, Ted Kaehler, Adele Goldberg (computer scientist), and others during the 1970s, influenced by Sketchpad and Simula. The language was generally released as Smalltalk-80 and has been widely used since. Smalltalk is in continuing active development, and has gathered a loyal community of users around it.

= History =

Smalltalk was invented by a group of researchers led by Alan Kay at Xerox Palo Alto Research Center; Alan Kay designed the system, which Dan Ingalls implemented. The first implementation, 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 version actually used for research work is now known as Smalltalk-72. Its syntax and execution model were very different from modern Smalltalk, so much so that it could be considered a different language.

After significant revisions which froze some aspects of executional semantics to gain performance, the version known as Smalltalk-76 was created. This version added inheritance, featured syntax much closer to Smalltalk-80, and had a development environment featuring most of the tools now familiar to Smalltalkers.

Smalltalk-80 added metaclasses, something which helps keep the everything is an object statement true by associating properties and behavior with individual classes (for example, to support different ways of creating instances). Smalltalk-80 was the first version made available outside of PARC, first as Smalltalk-80 Version 1, given to a small number of companies (HP, 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.

Two of the currently popular Smalltalk implementations 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, Xerox PARC spin-off company formed to bring Smalltalk to the market). As an interesting link between generations, [http://wiki.cs.uiuc.edu/VisualWorks/Smalltalk-80+in+a+box here] is a screenshot of Smalltalk-80 version 2 image running on Hobbes, a Smalltalk-80 VM implemented in VisualWorks.

IBM has indicated that VisualAge Smalltalk will be supported by partner company (and VisualAge implementors) Instantiations. Cincom, Dolphin, GemStone, and other vendors continue to sell Smalltalk environments. The open [http://www.squeak.org/ Squeak] implementation has a relatively active community of developers, including many of the original Smalltalk community. [http://www.gnu.org/software/smalltalk/ GNU Smalltalk] is a free ( has reimplemented many of Smalltalk s ideas, providing a more traditional syntax, an extensive standard library, while also borrowing concepts from other languages such as Perl and Python.

= Object-Oriented Programming =

In Smalltalk, an object is an instantiation of a Class (computer science), and every value is an object. In contrast to many other languages (eg, Java programming language), even primitive types such as integers and booleans are classes in Smalltalk. Objects in Smalltalk can do exactly three things:

  • Send a message to itself or another object.
  • Receive a message from itself or another object.
  • Hold state (references to other objects).
  • Importantly, an object cannot inspect or change the state of another object, and all communication is done by message passing. Any message can be sent to any object: the receiver determines whether that message is appropriate. Classes are also objects, and are instantiations of their metaclass. Each metaclass instantiates the class Metaclass , facilitating lexical closures. A code block can also be represented as a smalltalk object.

    =Syntax=

    Only a handful of behaviors are implemented in the language s minimalist syntax.

    ==Variable Declarations==

    Variable declarations in Smalltalk are enclosed by vertical bars, for example: | aString | Declares the variable aString. Multiple variables may be declared within one set of bars, so: | aString vowels |

    ==Value Assignment==

    A variable is assigned a value via the := syntax. So: vowels := aeiou Assigns the value aeiou to the previously declared vowels variable.

    ==Message Passing==

    Smalltalk message passing is achieved by the syntax object message The result of this message can be assigned to a variable: foo := bar baz Sends the message baz to the object bar , and assigns the returned value to the object foo . A message can also have arguments, consisting of one or more objects. This is achieved with: object message: argument1 Multiple arguments are separated by keyword parts which are delimited with colons, as in: object keywordPart1: arg1 keywordPart2: arg2 ... Concrete examples are: a at:1 put: hello or: anArray indexOf: 0 startingAt: 5 Finally, most of the special (non-alphabetic) characters can be used as binary messages. These allow for the well known mathematical and logical operators to be written in a traditional form: 4 * a Sends the message * to the receiver 4 passing the value of a as argument. Notice, that the Smalltalk language itself does not imply any semantic meaning of those operators. The outcome of the above is only defined by how the receiver of the message (in this case a Number-object) responds to the * -message. Thus, traditional operator-overloading is a side effect of this mechanism.

    ==Code Blocks==

    A block of code can be expressed as a literal object. This is achieved with square brackets: [ :params | ] Where :params is the list of parameters the code can take. This means that the Smalltalk code: [:x | x + 1] is equivalent to: f(x) = x + 1 Technically, the resulting block object is a closure. It can (at any time) access the variables of its enclosing lexical scopes. Just like any other object, references to blocks can be passed as argument, returned as value or stored as state. Eventually, blocks are asked to execute their code by sending them a value -message.

    =Control Structures=

    Smalltalk control structures are notably absent from the language syntax. These are instead implemented as messages sent to objects. For example, conditional execution is implemented by sending the message ifTrue: to a Boolean object, with the block of code to be executed if and only if the Boolean is True as the message argument. The following code demonstates 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.

    Collection>>select: aBlock | newCollection | newCollection := self species new. self do: [:each | (aBlock value: each) ifTrue: [newCollection add: each]]. ^newCollection 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 mesage 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, we can also use it like this:

    | rectangles aPoint| rectangles := OrderedCollection with: (Rectangle left: 0 right: 10 top: 100 bottom: 200) with: (Rectangle left: 10 right: 10 top: 110 bottom: 210). aPoint := Point x: 20 y: 20. collisions := rectangles select: [:aRect | aRect containsPoint: aPoint].

    =Classes=

    This is a stock class defintion: Object subclass: #MessagePublisher instanceVariableNames: classVariableNames: poolDictionaries: category: Smalltalk Examples Often, most of this definition will be filled in by the environment.

    ==Methods==

    When an object receives a message, a method matching the message name is invoked. The following code: publish Transcript show: Hello, World! Defines a method publish, and so defines what will happen when this object receives the publish message. Note that the pairing of a message with a method is done by the object at runtime (while in many languages this is determined statically at compile time).

    ==Instantiating Classes==

    The following code: MessagePublisher new Creates (and returns) a new instantiation 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=

    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. Transcript show: Hello, world! .

    Note that you need to have a Transcript window open in order to see the results of this example.

    =Image-based interpretation=

    Most Smalltalk systems are Image based instead of file based. Starting a Smalltalk image returns it entirely to its previous state, much like the hibernation mode of a laptop computer. Many popular programming languages are instead file based. Lisp is another language which is often implemented in a image based environment. This has many benefits such as debugging production issues offline, with full program state at the time of the error.

    =Level of Access=

    Everything in Smalltalk is available for modification from within a running program. This means that, for example, the Integrated development environment can be changed in a running system, without restarting it. In some implementations, you can also change the syntax of the language, or the garbage collection (computer science) implementation.

    =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 sharp.

    =Implementations=

    *Bistro programming language *Dolphin Smalltalk, see http://www.object-arts.com/Home.htm *F-Script programming language *GemStone/S, see http://www.gemstone.com/products/smalltalk/ *GNU Smalltalk, see http://www.gnu.org/software/smalltalk/smalltalk.html *International Business Machines VisualAge for Smalltalk, see http://www.ibm.com/software/awdtools/smalltalk/ *ObjectStudio, see [http://smalltalk.cincom.com Cincom Smalltalk website], [http://ostudio.swiki.net/1 Wiki], [http://www.cincomsmalltalk.com/blog/blogView Cincom Smalltalk Blog]. *LSW Vision-Smalltalk, see http://www.lesser-software.com/lswvst.htm *Pocket Smalltalk which runs on a Palm Pilot, see http://www.pocketsmalltalk.com/ *Self programming language *Smalltalk MT, see http://www.objectconnect.com/ *Smalltalk/X, see http://www.exept.de/exept/english/Smalltalk/frame_uebersicht.html *Squeak, see http://www.squeak.org/ *StepTalk (Uses Smalltalk language on top of the Objective-C runtime) *Strongtalk

  • see http://sourceforge.net/projects/susie/
  • *VisualWorks, see [http://smalltalk.cincom.com Cincom Smalltalk website], [http://wiki.cs.uiuc.edu/VisualWorks Wiki], [http://www.cincomsmalltalk.com/blog/blogView Cincom Smalltalk Blog].

    =See also=

    *walkback

    =External links=

    *[http://www.smalltalk.org/ Smalltalk.org] Advocacy site. *[http://www.whysmalltalk.com/ Why Smalltalk] Developer community. *[http://www.goodstart.com/ GoodStart] Advocacy site. *[http://dmoz.org/Computers/Programming/Languages/Smalltalk/ Open Directory: Smalltalk] *[http://gagne.homedns.org/%7etgagne/contrib/EarlyHistoryST.html The Early History of Smalltalk] by Alan C. Kay. *[http://www.bitsavers.org/pdf/xerox/alto/Smalltalk72_Manual.pdf Smalltalk-72 Instruction Manual] *[http://www.softcentral.com/informationspace/ Smalltalk information visualization tool] *[http://www.esug.org ESUG (European Smalltalk Users Group)]: A non-profit organization which gathers both industrial and academics. Has various Smalltalk promotion activities including a yearly event since 1993. *[http://swiki.agro.uba.ar/small_land/ Wiki con documentación de Smalltalk en español]

    =Books=

    *[http://www.iam.unibe.ch/~ducasse/FreeBooks.html Downloadable books about Smalltalk] Permission obtained to make these books freely available.