www.delorie.com/gnu/docs/smalltalk/gst_5.html   search  
 
Buy GNU books!


GNU Smalltalk User's Guide

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.3 Syntax of GNU Smalltalk

The language that GNU Smalltalk accepts is based on the file out syntax as shown in the Green Book, also known as Smalltalk-80: Bits of History, Words of Advice by Glenn Krasner. The entire grammar of GNU Smalltalk is described in the `libgst/gst.y' file, but a brief description may be in order:
 
<statements> !
executes the given statements immediately. For example,

 
16rFFFF printNl !
prints out the decimal value of hex FFFF, followed by a newline.

 
Smalltalk quitPrimitive !
exits from the system. You can also type a C-d to exit from Smalltalk if it's reading statements from standard input.

 
! class expression methodsFor: category name !
method definition 1 !
method definition 2 !
...
method definition n ! !

This syntax is used to define new methods in a given class. The class expression is an expression that evaluates to a class object, which is typically just the name of a class, although it can be the name of a class followed by the word class, which causes the method definitions that follow to apply to the named class itself, rather than to its instances. Two consecutive bangs terminate the set of method definitions. category name should be a string object that describes what category to file the methods in.

 
!Float methodsFor: 'pi calculations'!

radiusToArea
    ^self squared * Float pi !

radiusToCircumference
    ^self * 2 * Float pi ! !

It also bears mentioning that there are two assignment operators: _ and :=. Both are usable interchangeably, provided that they are surrounded by spaces. The GNU Smalltalk kernel code uses the := form exclusively, but _ is supported a) for compatibility with previous versions of GNU Smalltalk b) because this is the correct mapping between the assignment operator mentioned in the Blue Book and the current ASCII definition. In the ancient days (like the middle 70's), the ASCII underscore character was also printed as a back-arrow, and many terminals would display it that way, thus its current usage. Anyway, using _ may lead to portability problems.

The return operator, which is represented in the Blue Book as an up-arrow, is mapped to the ASCII caret symbol ^.

A complete treatment of the Smalltalk syntax and of the class library can be found in the included tutorial and class reference (see section `Class Reference' in the GNU Smalltalk Library Reference).

More information on the implementation of the language can be found in the Blue Book; the relevant parts are also available online as HTML documents, at http://users.ipa.net/~dwighth/smalltalk/bluebook/bluebook_imp_toc.html.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

  webmaster     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003