=== Top of the Swiki === Attachments ===

UsingCurlyBraces

You can use curly braces in Squeak to construct runtime-evaluated collections and do multiple value assignments. TimOlson

Curly braces are now used in Squeak to construct runtime-evaluated collections and to implement multiple-value assignment. For those of you who may not have seen it, Squeak lets you do the following:

1) Runtime-evaluated Collection Brace stacks can be used to create runtime-evaluated arrays almost as easily as literal arrays:

     {a. b-3. c squared}

     is equivalent to:

     Array with: a with: b-3 with: c squared

     any type of collection can be used by adding an as: message:

     {a. b-3. c squared} as: OrderedCollection

2) Multiple value assignment

Brace stacks on the left-hand-side of an assignment can be used to assign multiple values in parallel:

     {a. b} := #(1 2).    "a := 1. b := 2"
{a. b} := {b. a}. "swap"

3) caseOf: statements

One of the uses of 1) above is in building a runtime collection of block associations for caseOf: statements:

     stateMachineState caseOf:
{ [1] -> [(firstByte << 2) bitOr: (secondByte >> 6)].
[2] -> [(firstByte << 6) bitOr: (secondByte >> 2)]}.