Smalltalk method syntax on a postcard

TL;DR

This page shows nearly all the parts of Smalltalk method syntax in a single method, with live highlighting of the syntactic elements

Method syntax

The example below is a completely artificial method that does not perform any useful work, but it illustrates all the important elements of Smalltalk method syntax. Simply hover with the mouse over any of the Pharo constructs listed at the left (such as Unary), and all the corresponding syntactic elements in the example will be highlighted.

Note the classical structure of a method. The first line contains the message template with any formal parameters (in this case x). This is followed by a method comment within double quotes.

Many methods contain pragmas within angle brackets, for example to flag a method as an example method. This is followed by declaring any temporary variables used within or bar. Finally we have a number of statements consisting of assignments and message sends, separated by periods. A value may be returned by the method at the end (or anywhere else) using the return operator (^).

For a short video, see Smalltalk Syntax in 7'.