Literals (Constant
Expressions)
Numbers (Instances of class Number)
In the following, ==> means "prints as".
Decimal integer: 1234,
12345678901234567890
Octal integer: 8r177,
8r1777777777777777777777
Hex integer: 16rFF,
16r123456789ABCDEF012345
Arbitrary base integer: 2r1010 ==> 10
Integer with exponent: 123e2 ==> 12300,
2r1010e2 ==> 40
Float (double precision): 3.14e-10
Arbitrary base float: 2r1.1 ==> 1.5
Float with exponent: 2r1.1e2 ==> 6.0
- Squeak supports SmallInteger arithmetic (integers
between -230 and 230-1) with fast
internal primitives.
- Squeak supports arbitrary precision arithmetic
seamlessly (automatically coercing SmallInteger to
LargePositiveInteger and LargeNegativeInteger where
appropriate), albeit at a slight cost in speed.
- Squeak supports several other kinds of "numeric"
value, such as Fractions (arbitrary precision rational
numbers) and Points. While there are no literals for
these objects, they are naturally expressed as operations
on built-in literals. ( "2/3" and "2@3",
respectively)
- Numbers may be represented in many radices, but the
radix specification itself is always expressed in base
10. The base for the exponent part is the same as the
radix. So: 2r1010 ==> 10, 10e2 ==>
1000 (=10 x 102), but 2r1010e2 ==>
40 (=10 x 22)
Characters (Instances of class Character)
$x "A character is any character (even unprintable
ones), preceded by a dollar sign"
$3 "Don't be shy about characters that are
digits"
$< "or symbols"
$$ "or even the dollar sign"
Strings (Instances of class String)
'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 doubling'' them'
'strings can contain embedded
newline characters'
'' "and don't forget the empty string"
- A string is very much like ("isomorphic to") an array
containing characters. Indexing a string answers
characters at the corresponding position, staring with
1.
Symbols (Instances of class Symbol)
#'A string preceded by a hash sign is a
Symbol'
#orAnyIdentifierPrefixedWithAHashSign
#orAnIdentifierEndingWithAColon:
#or:several:identifiers:each:ending:with:a:colon:
#- "A symbol can also be a
hash followed by '-' or any special character"
#+< "or a hash followed by any pair of
special characters"
- Symbol is a subclass of String, and understands, in
large part, the same messages.
- The primary difference between a symbol and a string
is that all symbols comprising the same sequence of
characters are the same instance. Two different string
instances can both have the characters 'test one two
three', but every symbol having the characters #'test one
two three' is the same instance. This "unique instance"
property means that Symbols can be efficiently compared,
because equality (=) is the same as identity (==).
- "Identifier with colon" Symbols (e.g.,
#a:keyword:selector:) are often referred to as keyword
selectors, for reasons that will be made clear
later.
- "Single or dual symbol" Symbols (e.g., #* or
#++) are often referred to as binary selectors.
- The following are permissible special characters:
+/*\~<=>@%|&?!
- Note that #-- is not a symbol (or a binary selector).
On the other hand, #'--' is a symbol (but not a
binary selector).
Constant Arrays (Instances of class Array)
#( 1 2 3 4 5 ) "An array of size 5
comprising five Integers (1 to 5)"
#( 'this' #is $a #'constant' array ) "An array
of size 5 comprising a String ('this'), a Symbol (#is), a
Character ($a) and two Symbols (#constant and #array)."
#( 1 2 ( 1 #(2) 3 ) 4 ) "An array of size 4
comprising two Integers (1 and 2), an Array of size 3, and
another Integer (4)."
#( 1 + 2 ) "An array of size 3 comprising 1,
#+, and 2. It is not the singleton array comprising
3."
- Constant arrays are constants, and their elements
must therefore be constants. "Expressions" are not
evaluated, but are generally parsed as sequences of
symbols as in the example above.
- Constant arrays may contain constant arrays. The hash
sign for internal constant arrays is optional.
- Identifiers and sequences of characters in constant
arrays are treated as symbols; the hash sign for internal
symbols is optional.
- Arrays are indexed with the first element at index
1.
|