Squeak Smalltalk: Language Reference


Version 0.0, 20 November 1999, by Andrew C. Greenberg, werdna@mucow.com
Version 1.2, 26 April 2001, by Andrew P. Black,
black@cse.ogi.edu

Based on:
    Smalltalk-80: The Language and Its Implementation, Author: Adele Goldberg and David Robson
    Squeak Source Code, and the readers of the Squeak mailing list.

Squeak site: www.squeak.org


Contents

  • Using Squeak
  • Squeak Smalltalk Syntax
  • See also the Squeak Classes Reference page


    Using Squeak: the Basics

  • Mousing Around
  • System Menus
  • System Key Bindings
  • Mousing Around

    Squeak (and the Smalltalk-80 from which it was spawned) assumes a machine with a three-button mouse (or its equivalent). These buttons were referred to as "red," "yellow" and "blue." The red button was conventionally used for selecting "things," the yellow button was conventionally used for manipulating "things" within a window and the blue button was conventionally used for manipulating windows themselves. Conventions, of course, are not always followed.

    Since many modern mice no longer have three buttons, let alone colored ones, various mapping conventions are used:

    For uncolored three-button mice, the usual mapping is:

    left-mouse

    ->

    red

    middle-mouse

    ->

    yellow

    right-mouse

    ->

    blue

    spacer Windows machines with three button mice can be made to conform to this mapping by right clicking the Windows title bar of Squeak, and selecting VM Preferences >> Use 3 button mouse mapping. Otherwise, for Windows machines with two button mice, the mapping is:

    left-mouse

    ->

    red

    right-mouse

    ->

    yellow

    alt-left-mouse

    ->

    blue

    MacOS Systems generally have one mouse button. The mapping is:

    mouse

    ->

    red

    option-mouse

    ->

    yellow

    spacer -mouse

    ->

    blue

    It is worthwhile purchasing a 3-button mouse for your computer. I put colored labels on my buttons while I was training my fingers. I also chose a different mapping.

    If you have a mouse with a scrolling wheel, map "wheel up" to command-upArrow and "wheel down" to command-downArrow, and you will be able to use the wheel to control scrolling in Squeak.

    System Menus

    Squeak provides access to certain Smalltalk services through its system menus, some of which are depicted below:

    spacer

    The Main Menu. The World menu, sometimes called the "main menu," can be reached by clicking the red button while the mouse points to the background of a system project. From this menu, you can save the image and changes files, save them in files with a different name, and terminate execution of the Squeak virtual machine. You can also access many other menus ... including the four shown here.

    The open Menu provides access to many system tools, including system browsers, workspaces, change sorters, transcripts and file lists, as well as end user tools such as an email agent (Celeste) and web browser (Scamper).

    The help Menu provides access to certain on-line help facilities as well as a preferences dialog, some environment enquiries, a dictionary and facilities for updating your version of Squeak.

    The windows and flaps Menu provides access to services for manipulating system windows and (in Morphic only) flaps. Flaps are small tabs at the side of the screen that pull out like drawers and provide quick access to whatever you place there. Try them! The Tools flap is a very convenient way of getting new system tools (rather than using the open menu).

    The appearance menu lets the user change various aspects of the systems appearance. In particular, it provides a way of adjusting the display depth and going in and out of full screen mode.

    System Key Bindings

    Applications that use standard Squeak text container widgets, including System Browsers, Workspaces, File Lists and Transcripts, provide facilities for manipulating the text and providing access to other system functionality. Many of these facilities can be reached by using the red-button menus, but many are more conveniently accessed using special key sequences. Of course, particular applications can use some, all or of none of these. In the following tables, a lower-case or numeric command "key" can be typed by simultaneously pressing the key and the Alt key (on Windows) or the spacer key (on MacOS). Upper-case keys are typed by simultaneously pressing either Shift-Alt (or Shift-spacer ) and the indicated key, or ctrl and the indicated key. Other special key presses are indicated below in square brackets.

    General Editing Commands

    Key

    Description

    Notes

    z

    Undo

     

    x

    Cut

     

    c

    Copy

     

    v

    Paste

     

    a

    Select all

     

    D

    Duplicate. Paste the current selection over the prior selection, if it is non-overlapping and legal

    1

    e

    Exchange. Exchange the contents of current selection with the contents of the prior selection

    1

    y

    Swap. If there is no selection, swap the characters on either side of the insertion cursor, and advance the cursor. If the selection has 2 characters, swap them, and advance the cursor.

     

    w

    Delete preceding word

     

    Notes

    1. These commands are a bit unusual: they concern and affect not only the current selection, but also the immediately preceding selection.

    Search and Replace

    Key

    Description

    Notes

    f

    Find. Set the search string from a string entered in a dialog. Then, advance the cursor to the next occurrence of the search string.

     

    g

    Find again. Advance the cursor to the next occurrence of the search string.

     

    h

    Set Search String from the selection.

     

    j

    Replace the next occurrence of the search string with the last replacement made

     

    A

    Advance argument. Advance the cursor to the next keyword argument, or to the end of string if no keyword arguments remain.

     

    J

    Replace all occurrences of the search string with the last replacement made

     

    S

    Replace all occurrences of the search string with the present change text

     

    Cancel/Accept

    Key

    Description

    Notes

    l

    Cancel (also "revert"). Cancel all edits made since the pane was opened or since the last save

     

    s

    Accept (also "save"). Save the changes made in the current pane.

     

    o

    Spawn. Open a new window containing the present contents of this pane, and then reset this window to its last saved state (that is, cancel the present window).

     

    Browsing and Inspecting

    Key

    Description

    Notes

    b

    Browse "it" (where "it" is a class name). Opens a new browser.

    1

    d

    Do "it" (where "it" is a Squeak expression)

    1

    i

    Inspect "it": evaluate "it" and open an inspector on the result. ("it" is a Squeak expression). Exception: in a method list pane, i opens an inheritance browser.

    1

    m

    Open a browser of methods implementing "it" (where "it" is a message selector)

    1,2

    n

    Open a browser of methods that send "it" (where "it" is a message selector).

    1,2

    p

    Print "it". Evaluate "it" and insert the results immediately after "it." (where "it" is a Smalltalk expression)

    1

    B

    Set the present browser to browse "it" (where "it" is a class name)

    1

    E

    Open a browser of methods whose source contain strings with "it" as a substring.

    1

    I

    Open the Object Explorer on "it" (where "it" is an expression)

    1

    N

    Open a browser of methods using "it" (where "it" is an identifier or class name)

    1

    O

    Open single-message browser (in selector lists)

    1

    W

    Open a browser of methods whose selectors include "it" as a substring.

    1

    Notes:

    1. A null selection will be expanded to a word, or to the whole of the current line, in an attempt to do what you want.
    2. For these operations, "it" means the outermost keyword selector in a large selection.

    Special Conversions and Processing

    Key

    Description

    Notes

    C

    Open a workspace showing a comparison of the selection with the contents of the clipboard

     

    U

    Convert linefeeds to carriage returns in selection

     

    X

    Force selection to lowercase

     

    Y

    Force selection to uppercase

     

    Z

    Capitalize all words in selection

     

    Smalltalk Program Data Entry

    Key

    Description

    Notes

    q

    Attempt to complete the selection with a valid and defined Smalltalk selector. Repeated commands yield additional selectors.

     

    r

    Recognizer. Invoke the Squeak glyph character recognizer. (Terminate recognition by mousing out of the window)

     

    F

    Insert 'ifFalse:'

     

    T

    Insert 'ifTrue:'

     

    V

    Paste author's initials, date and time.

     

    L

    Outdent (move selection or line one tab-stop left)

     

    R

    Indent (move selection or line one tab stop right)

     

    [Ctl-return]

    Insert return followed by as many tabs as the previous line (with a further adjustment for additional brackets in that line)

     

    [shift-delete]

    Forward delete. Or, deletes from the insertion point to the beginning of the current word.

     

    Bracket Keys

    These keys are used to enclose (or un-enclose, if the selection is already enclosed) the selection in a kind of "bracket". Conveniently, double clicking just inside any bracketed text selects the entire text, but not the brackets.

    Key

    Description

    Notes

    Control-(

    Enclose within ( and ), or remove enclosing ( and )

     

    Control- [

    Enclose within [ and ], or remove enclosing [ and ]

     

    Control- {

    Enclose within { and }, or remove enclosing { and }

     

    Control- <

    Enclose within < and >, or remove enclosing < and >

     

    Control- '

    Enclose within ' and ', or remove enclosing ' and '

     

    Control- "

    Enclose within " and ", or remove enclosing " and "

     

    Keys for Changing Text Style and Emphasis

    Key

    Description

    Notes

    k

    Set font

     

    u

    Align

     

    K

    Set style

     

    1

    10 point font

     

    2

    12 point font

     

    3

    18 point font

     

    4

    24 point font

     

    5

    36 point font

     

    6

    Brings up a menu, providing choice of color, action-on-click, link to class comment, link to method, url.. To remove these properties, select more than the active part and then use command-0.

     

    7

    bold

     

    8

    italic

     

    9

    narrow (same as negative kern)

     

    0

    plain text (removes all emphasis)

     

    - (minus)

    underlined (toggles it)

     

    =

    struck out (toggles it)

     

    _ (a.k.a. shift -)

    negative kern (letters 1 pixel closer)

     

    + (a.k.a. shift =)

    positive kern (letters 1 pixel further apart)

     


    Squeak Smalltalk Syntax: the Basics

  • Pseudo-variables
  • Identifiers
  • Comments
  • Literals
  • Assignments
  • Messages
  • Expression Sequences
  • Cascades
  • Expression Blocks
  • Control Structures
  • Brace Arrays
  • Class Definition
  • Method Definition
  • Pseudo-Variables

    Pseudo-variable

    Description

    nil

    The singleton instance of Class UndefinedObject

    true

    The singleton instance of Class True

    false

    The singleton instance of Class False

    self

    The current object, that is, the receiver of the current message.

    super

    As the receiver of a message, super refers to the same object as self. However, when a message is sent to super, the search for a suitable method starts in the superclass of the class whose method definition contains the word super.

    thisContext

    The active context, that is, the "currently executing" MethodContext or BlockContext.

    • Pseudo-variables are reserved identifiers that are similar to keywords in other languages.
    • nil, true and false are constants.
    • self, super and thisContext vary dynamically as code is executed.
    • It is not possible to assign to any of these pseudo-variables.

    Identifiers

            letter (letter | digit )*

    • Smalltalk identifiers (and symbols) are case-sensitive.
    • It is a Smalltalk convention for identifiers (instance and temporaries) of several words to begin with a lower case character, and then capitalize subsequent words. (e.g., thisIsACompoundIdentifier).
    • Certain identifiers, for example, globals (e.g., Smalltalk) and class variables, are by convention initially capitalized. The names of all classes are also global variables (e.g., SystemDictionary).

    Comments

    "a comment comprises any sequence of characters, surrounded by double quotes"
    "
    comments can include the 'string delimiting' character"
    "
    and comments can include embedded double quote characters by ""doubling"" them"
    "
    comments can span many
    many
    lines"

    Literals (Constant Expressions)

    Numbers (Instances of class Number)

    In the following, ==> means "prints as".

    Decimal integer: 1234, 12345678901234567890
    Octal integer: 8r177, 8r1777777777777777777777
    Hex integer: 16rFF, 16r123456789ABCDEF012345
    Arbitrary base integer: 2r1010 ==> 10
    Integer with exponent: 123e2 ==> 12300, 2r1010e2 ==> 40
    Float (double precision): 3.14e-10
    Arbitrary base float: 2r1.1 ==> 1.5
    Float with exponent: 2r1.1e2 ==> 6.0

    • Squeak supports SmallInteger arithmetic (integers between -230 and 230-1) with fast internal primitives.
    • Squeak supports arbitrary precision arithmetic seamlessly (automatically coercing SmallInteger to LargePositiveInteger and LargeNegativeInteger where appropriate), albeit at a slight cost in speed.
    • Squeak supports several other kinds of "numeric" value, such as Fractions (arbitrary precision rational numbers) and Points. While there are no literals for these objects, they are naturally expressed as operations on built-in literals. ( "2/3" and "2@3", respectively)
    • Numbers may be represented in many radices, but the radix specification itself is always expressed in base 10. The base for the exponent part is the same as the radix. So: 2r1010 ==> 10, 10e2 ==> 1000 (=10 x 102), but 2r1010e2 ==> 40 (=10 x 22)

    Characters (Instances of class Character)

    $x "A character is any character (even unprintable ones), preceded by a dollar sign"
    $3 "Don't be shy about characters that are digits"
    $< "or symbols"
    $$ "or even the dollar sign"

    Strings (Instances of class String)

    'a string comprises any sequence of characters, surrounded by single quotes'
    '
    strings can include the "comment delimiting" character'
    '
    and strings can include embedded single quote characters by doubling'' them'
    '
    strings can contain embedded
    newline characters'
    ''
    "and don't forget the empty string"

    • A string is very much like ("isomorphic to") an array containing characters. Indexing a string answers characters at the corresponding position, staring with 1.

    Symbols (Instances of class Symbol)

    #'A string preceded by a hash sign is a Symbol'
    #
    orAnyIdentifierPrefixedWithAHashSign
    #orAnIdentifierEndingWithAColon:
    #or:several:identifiers:each:ending:with:a:colon:
    #-     "A symbol can also be a hash followed by '-' or any special character"
    #+<  "or a hash followed by any pair of special characters"

    • Symbol is a subclass of String, and understands, in large part, the same messages.
    • The primary difference between a symbol and a string is that all symbols comprising the same sequence of characters are the same instance. Two different string instances can both have the characters 'test one two three', but every symbol having the characters #'test one two three' is the same instance. This "unique instance" property means that Symbols can be efficiently compared, because equality (=) is the same as identity (==).
    • "Identifier with colon" Symbols (e.g., #a:keyword:selector:) are often referred to as keyword selectors, for reasons that will be made clear later.
    • "Single or dual symbol" Symbols (e.g., #* or #++) are often referred to as binary selectors.
    • The following are permissible special characters: +/*\~<=>@%|&?!
    • Note that #-- is not a symbol (or a binary selector). On the other hand, #'--' is a symbol (but not a binary selector).

    Constant Arrays (Instances of class Array)

    #( 1 2 3

    gipoco.com is neither affiliated with the authors of this page nor responsible for its contents. This is a safe-cache copy of the original web site.