Integers are read in as an arbitrary-precision sequence of digits, without separators.
Floats are read in as an arbitrary-precision sequence of digits, with a period noting the decimal position.
Integers or Floats may be entered with radix up to 36, using the digits 0 to 9 and then A to Z in order, by prefixing the literal with the radix (numeric base) and 'r'. So 3r100 evaluates to 9, and 2r0.1 evaluates to 0.5. Case is disregarded for the extra-decimal digits. The Float radix notation is always read in as a Float, and not an infinite-precision Fraction.
Slate's default support for character literals uses the $ symbol as a prefix. For example, $a, $3, $>, and $$ are all Character object literals for a, 3, >, and $, respectively. Printable and non-printable characters require backslash escapes as shown and listed in Table cap:Character-Literal-Escapes.
|
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:
'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"
Symbol literal syntax starts with the pound sign character (#) and consists of all following characters up to the next non-escaped whitespace or reserved character (whichever comes first), unless the pound sign is followed exactly by a string literal (in single quotes), in which case the string's contents become the identifier for the Symbol. So, for example, the following are all valid Symbols and Symbol literals:
#20
#+
#key:word:expression:
#something_with_underscores
#'A full string with a \nnewline in it.'
#'@'
Internally, Slate currently keeps one global table for Symbols, and uses individual context objects to hold local bindings.5
Arrays can be literally and recursively specified by curly-brace notation using stops as separators. Array indices in Slate are 0-based. So:
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:
Block syntax basics were covered in 2.1.1; the precise, full specification includes more features and outlines some necessary logical rules. Primarily, blocks are square-bracket-delimited statement sequences with an optional header that specifies input and local slots (input slots being arguments).
Slot names must be valid unary message selectors (see 2.2.1). Inputs are distinguished by a prefix colon character (:), and must occur in the same positional order that the invocation will use or expect, although they can be interspersed among other slot declarations at will.
Optional keyword arguments are specified with an ampersand prefix character (&), and may occur in any order.
For example,
A single ``rest'' parameter which becomes an array containing all extra positional (non-keyword) arguments passed may be specified once in the header in any position relative to the other parameters, prefixed with an asterisk (e.g. *rest).
Blocks may be used to perform arbitrary compile-time calculations, using the #-prefix as used for literal arrays and strings. So #[3 + 4] will result in 7 in the resulting code for the surrounding context (perhaps a method or top-level expression), as though the block were never there.