4.8: Chapter Summary
- Page ID
- 40089
\( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)
- Pharo has only six reserved identifiers (also called pseudo-variables):
true
,false
,nil
,self
,super
, andthisContext
. - There are five kinds of literal objects: numbers (5, 2.5, 1.9e15, 2r111), characters (
$a
), strings ('hello'
), symbols (#hello
), and arrays (#('hello' #hi)
or{ 1 . 2 . 1 + 2 }
) - Strings are delimited by single quotes, comments by double quotes. To get a quote inside a string, double it.
- Unlike strings, symbols are guaranteed to be globally unique.
- Use
#( ... )
to define a literal array. Use{ ... }
to define a dynamic array. Note that#(1+2) size >>> 3
, but{1+2} size >>> 1
- There are three kinds of messages: unary (e.g.,
1 asString
,Array new
), binary (e.g.,3 + 4
,'hi'
,'there'
), and keyword (e.g.,'hi' at: 2 put: $o
) - A cascaded message send is a sequence of messages sent to the same target, separated by semi-colons:
OrderedCollection new add: #calvin; add: #hobbes; size >>> 2
- Local variables are declared with vertical bars. Use
:=
for assignment.|x| x := 1
- Expressions consist of message sends, cascades and assignments, evaluated left to right (and optionally grouped with parentheses). Statements are expressions separated by periods.
- Block closures are expressions enclosed in square brackets. Blocks may take arguments and can contain temporary variables. The expressions in the block are not evaluated until you send the block a value message with the correct number of arguments.
[ :x | x + 2 ] value: 4
- There is no dedicated syntax for control constructs, just messages that conditionally evaluate blocks.