[squeak-dev] Block argument syntax

Bert Freudenberg bert at freudenbergs.de
Fri Mar 1 20:27:23 UTC 2013


Here's an additional idea - using "empty" keywords for optional method arguments (from http://piumarta.com/pepsi/pepsi.html):

3.4   Method definitions

Methods are just 'named blocks', tied to a particular prototype only by permitting direct access to the state within that prototype. (Therein lies yet another reason to abolish direct access to state.) This is reflected in the syntax of the top-level form for adding methods (named blocks) to a prototype:
name pattern [ statements ]
where name identifies a prototype object (defined as described above), pattern looks (more or less) like a Smallalk-80 message pattern, and statements is a block (notice the brackets) providing the behaviour for the method. The pattern component can be a unary, binary or keyword message pattern.
Extensions to Smalltalk's fixed-arity messages include additional and variadic formal arguments. Additional formal arguments for unary and keyword selectors are written like block arguments and can appear before or after the initial opening bracket. For example, two additional formal arguments could be written

name selector :arg1 :arg2 [ statements ]
name selector [ :arg1 :arg2 | statements ]
(where selector is a unary or keyword selector). Unary or keyword message sends can pass additional actual arguments by prefixing each additional argument with a colon. To ask the receiver to add two numbers:
Object add :x :y
[
  ^x + y
]

[
  | sum |
  sum := self add :3 :4.
]
Variadic arguments can be attached to unary or keyword methods. This is indicated by an ellipsis in the message pattern immediately following the last named argument. The pattern for unary and keyword syntax therefore also includes:
name unarySelector ... [ statements ]
name keywords: arguments ... [ statements ]
(Simply for lack of time, there is currently no friendly syntax to recover the 'rest' arguments within the body of a message. Wizards, however, can easily recover these arguments by writing some low-level magic inside a method body.)

- Bert -

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20130301/95325b00/attachment.htm


More information about the Squeak-dev mailing list