next up previous contents
Next: 3 The Slate World Up: 2 Language Reference Previous: 2.3 Methods   Contents

Subsections

2.4 Literal Syntax

2.4.1 Characters

Slate's default support for character literals uses the $ symbol as a prefix. The following printable and non-printable characters require backslash escapes as follows:

Character name Literal
Escape

All other symbols can be immediately be preceded by $ in order to construct the Character object for them, for example,

$a, $3, $>, and $$

are all Character object literals for a, 3, >, and $, respectively.

2.4.2 Strings

Strings are comprised of any sequence of characters surrounded by single-quote characters. Strings can include the commenting character (double-quotes) without an escape. Embedded single-quotes can be provided by using the backslash character to escape them (\'). Slate's character literal syntax also embeds into string literals, omitting the $ prefix. All characters that require escapes in character literal syntax also require escapes when used within string literals, with the exception of double-quote marks and the addition of single-quote marks.

The following are all illustrative examples of Strings in Slate:

'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 escaping\' them' 
'strings can contain embedded 
newline characters' 
'and escaped \ncharacters' 
'' "and don't forget the empty string"

2.4.3 Symbols

Symbols start with the pound sign character (#) and consist of all following characters up to the next non-escaped whitespace, unless the pound sign is followed exactly by a string literal, in which case the string's contents become the identifier for the symbol. So, for example, #@, #key:word:expression:, #something_with_underscores, and #'A full string with a \nnewline in it.' are all valid symbols and symbol literals.

A property of Symbols and their literals is that any literal with the same value as another also refers to the same instance as any other symbol literal with that value in a Slate system. This allows fast hashes and comparisons by identity rather than value hashes. In particular, as with Slate identifiers, a Symbol's value is case-sensitive, so #a and #A are distinct.

Internally, Slate currently keeps one global table for symbols, and uses individual context objects to hold local bindings.3

2.4.4 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 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.


next up previous contents
Next: 3 The Slate World Up: 2 Language Reference Previous: 2.3 Methods   Contents
The Slate Project 2003-07-29