*** Welcome to piglix ***

GNU Smalltalk

GNU Smalltalk
GNU Smalltalk logo.svg
Original author(s) Steve Byrne, Paolo Bonzini
Stable release
3.2.5 / April 11, 2013; 3 years ago (2013-04-11)
Operating system Unix (Linux, Cygwin, Mac OS X/Darwin)
Type Programming language
License GPL + LGPL
Website http://smalltalk.gnu.org/

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. In this way, GNU Smalltalk acts more like an interpreter rather than an environment in the traditional Smalltalk manner.

GNU Smalltalk includes bindings for many free software libraries including SQLite, libSDL, cairo, gettext, and Expat.

These examples only work on GNU Smalltalk 3.0 and later versions. Classic Hello world example:

Some basic Smalltalk code:

Constructing and using an array:

Constructing and using a hash:

Parameter-passing a block to be a closure:

Returning closures from a method:

Using block to send info back to the caller:

Invoke the above method, passing it a block:

Iterating over enumerations and arrays using blocks:

A method such as inject:into: can accept both a parameter and a block. It iterates over each member of a list, performing some function on while retaining an aggregate. This is analogous to the foldl function in functional programming languages. For example:

On the first pass, the block receives 10 (the argument to inject) as sum, and 1 (the first element of the array) as element, This returns 11. 11 then becomes sum on the next pass, which is added to 3 to get 14. 14 is then added to 5, to finally return 19.

Blocks work with many built-in methods:

Using an enumeration and a block to square the numbers 1 to 10:

The following code defines a class named Person. By deriving from Magnitude, it automatically defines all comparison methods except one (<). With the addition of that one, asSortedCollection can sort by age. Note that we can override the way the object is printed/displayed (the default is to share the programmer-print and user-display representation) by overriding printOn:.


...
Wikipedia

...