next up previous contents
Next: Blocks Up: Literals Previous: Symbols   Contents

Arrays

Arrays can be literally and recursively specified by curly-brace notation using stops as separators. Array indices in Slate are 0-based. So:

{4. 5. {foo. bar}}.
returns an array with 4 in position 0, 5 at 1, and an array with objects foo and bar inserted into it at position 2.

Immediate array syntax - #{4. 5. {foo. bar}} - is provided as an alternative to create the array when the method is compiled, instead of creating a new array on each method invocation. The syntax is identical except that the first opening brace is preceded by the pound sign. The disadvantage is that no run-time values will be usable.

A special ``literal array'' syntax is also provided, in the manner of Smalltalk-80, in which all tokens within are treated symbolically, evaluating to an array of literals as read (but not evaluated) by Slate. Naturally, these are all evaluated when the surrounding context is compiled. For example:

Slate> #(1 2 3). 
{1. 2. 3} 
Slate> #(3 + 4). 
{3. #'+'. 4} 
Slate> #(quux: a :bar). 
{#quux:. #a. #:bar} 
Slate> #(1 . _ 2e3). 
{1. #'.'. #_. 2000.0}



Brian Rice 2004-08-24