Frequently Asked Questions - Features

Can GNU Smalltalk programs access databases?

Yes, versions starting with 3.0 have a DBI-like library supporting PostgreSQL, MySQL and SQLite. In addition, you can use Glorp to map objects and relational databases.

Does GNU Smalltalk support Unicode and MBCS?

Yes. Strings however are processed (e.g. read from a file) byte-per-byte. If you need per-character processing, you should load the Iconv package and convert strings to UnicodeString, using the #asUnicodeString method.

Regular expression matching cannot operate directly on UnicodeString objects. This means that regular expression matching will not work with most multi-byte character encodings (it will work with UTF-8).

What is VFS?

VFS is GNU Smalltalk's Virtual FileSystem layer. VFS allows GNU Smalltalk programs to use archive files (.gz, .tar, .zip, etc.) and URLs transparently. The first implementation of VFS was inspired by the homonymous feature of the Midnight Commander, later incorporated in GNOME and now called GVFS.

VFS is a fundamental part of the implementation of .star packages.

What are .star packages?

Starting from version 3.0, GNU Smalltalk supports grouping multiple files for a single package into a single archive. These are just .zip files, but they are rebranded .star (Smalltalk archive) for this purpose.

A valid .star file must include an XML description of the package in the top directory, in a file that must be called package.xml.

GNU Smalltalk includes gst-package, a tool to create and install .star files. Projects hosted on this site can be downloaded into a .star file using it, using a command like:

gst-package --download Iliad

to install the package system-wide, or

gst-package -t ~/.st --download Iliad

to install it in your home directory.

What is a generator?

A generator is a quick way to create a Stream. As you might have seen in an earlier question, streams are a powerful iteration tool that Smalltalk offers. A generator is a kind of pluggable stream, in that a user-supplied blocks defines which values are in a stream.

For example, here is an empty generator and two infinite generators:

Generator on: [ :gen | ]
Generator on: [ :gen | [ gen yield: 1 ] repeat ]
Generator inject: 1 into: [ :value | value + 1 ]

As a more concrete example, these lines process a file and create Person objects out of the file:

lines := file lines.
lines := lines select: [ :line | line ~ '^[A-Za-z]+ [0-9]+$' ].
fields := lines collect: [ :line | line subStrings ].
people := fields collect: [ :data |
            Person name: data first age: data second asInteger ].

Let's see how to rewrite them to use a single Generator instead:

Generator on: [ :gen |
    file linesDo: [ :line || data |
        line ~ '^[A-Za-z]+ [0-9]+$' ifTrue: [
            data := line subStrings.
            gen yield: (Person name: data first age: data second asInteger) ] ] ].

As you can see, #select: becomes an if-statement, and the value from the final stream is yielded to the user of the generator.

Generators use continuations, but they shield the users from their complexity by presenting the same simple interface as streams.

Does GNU Smalltalk run Seaside?

The first stable version supporting Seaside will be 3.1.

The first release candidate, 3.0a, was released on March 7th 2008.

How do I download a document from the web?

First, make sure the NetClients package is loaded. You can use this Smalltalk code:

PackageLoader fileInPackage: 'NetClients'

Alternatively, you can create a separate image that preloads the package (that's explained in another FAQ).

Once you have the package loaded, you can open a FileStream on a remote URL just like you would do for a local file:

(FileStream open: '' mode: FileStream read) contents

What is a continuation and why should I care?

A continuation object contains a snapshot of the program execution including all the local variables, and allows to restore the execution of the program from where the object was created. GNU Smalltalk supports continuations.

You will probably never use continuations directly, but they enable doing very interesting things, such as generators and continuation-based web frameworks.

How do threads work?

GNU Smalltalk uses preemptive green (non-native) threads; that is, multiple Smalltalk processes are run by the virtual machine in one operating system thread. The main disadvantage to this approach is that it is impossible to use multiple CPUs even when the machine has them available; for single-processor CPUs, green threads are faster than operating system threads, because they make context switches cheaper.

Threads are not preempted after a given amount of time, but other events could in general cause the current thread to be suspended: a higher priority process being resumed, a timer being fired, or I/O becoming possible.

Is it possible to set breakpoints or watch conditions?

Not yet, though there is a minimal debugger example included in the examples, as well as support for debugging in the VM.

User login