Literals

Literal arrays are read-only in Pharo (modifying #(1 2 3) at: 1 put: 9 raises a ModificationForbidden error because recent Pharo versions mark literals read-only).

6.1 Numbers

42                  "SmallInteger"
-17
1000000000000000000000      "LargePositiveInteger — automatic, unlimited precision"
3.14159             "Float (64-bit double)"
1.5e10   2.5e-3     "Float with exponent"
1e100               "an Integer in Pharo (exponent on an integer literal keeps it integral)"
16rFF               "255 — radix notation: base r digits"
2r1010              "10"
8r777               "511"
36rSMALLTALK        "base 36"
3/4                 "not a literal: the message #/ creates a Fraction (3/4)"
3.14s2              "ScaledDecimal 3.14s2 — exact decimal with 2 digits of scale"
1/3 + (2/3)         "→ 1 — exact rational arithmetic"

6.2 Characters

$a          "the character a"
$           "the space character (dollar followed by a space)"
$'          "a quote character"
Character cr.  Character tab.  Character space.  Character value: 65.  "→ $A"

6.3 Strings and symbols

'Hello, world'          "String"
'It''s easy'            "embedded quote: double it"
#foo                    "Symbol — a unique, immutable string"
#at:put:                "keyword selector symbol"
#+                      "binary selector symbol"
#'hello world'          "symbol with spaces"

6.4 Literal arrays, byte arrays, and dynamic arrays

Literal arrays are read-only in Pharo (modifying #(1 2 3) at: 1 put: 9 raises a ModificationForbidden error because recent Pharo versions mark literals read-only). Use #(1 2 3) copy or Array with: 1 with: 2 with: 3 for a mutable one.

#(1 2 3)                    "literal Array — elements are literals, created at compile time"
#(1 $a 'str' #sym 3.5)      "heterogeneous"
#(foo bar baz)              "inside a literal array, bare words are Symbols: #(#foo #bar #baz)"
#(true false nil)           "→ booleans and nil"
#(1 #(2 3) 4)               "nested arrays"
#[1 2 255]                  "ByteArray (values 0–255)"
{ 1 + 1. 'two'. 3 factorial }   "dynamic (brace) Array — elements are evaluated expressions → #(2 'two' 6)"

6.5 Other literal-like expressions

These are ordinary messages, not syntax — but they are so common that they read like literals.

3 @ 4           "a Point (sent #@)"
#key -> 'value' "an Association (sent #->)"
1 to: 5         "an Interval"