REFERENCE · Pharo course

Reference Card

Pharo Syntax on One Card

The whole language fits here. Everything else is objects and messages.

Literals — values you write directly

KindExamples
Integer / Float42   -7   3.14   2r1010 "binary 10"
Fraction3/4 "a real Fraction, not 0.75"
Character$A   $z   $ "dollar + one char"
String'hello'   'it''s' "double '' to escape"
Symbol#count   #+ "unique, interned"
Array (literal)#(1 2 3 $a 'x' #sym)
Array (dynamic){ 1+1. 2 factorial } "evaluated"
Boolean / niltrue   false   nil

The three messages — this is the whole grammar

TypeShapeExamplePrecedence
Unaryreceiver selector5 factorial1st (tightest)
Binaryreceiver op arg3 + 42nd
Keywordrecv k1: a1 k2: a2arr at: 1 put: 93rd (loosest)
The one rule unary > binary > keyword, then left→right within a level. No arithmetic precedence. 2 + 3 * 420. Use ( ) to override. The selector of at:put: is the single name #at:put:.

The punctuation

SymbolMeansExample
:=assignmentcount := 0
.statement separatora := 1. b := 2
;cascade — more messages to the same receiverc increment; increment; reset
^return from method^ count
"..."comment"this is a comment"
[ :x | ... ]block (a closure); :x is a parameter[ :x | x * x ]

Cascade vs. chain — the classic confusion

c increment; increment; count   "cascade: 3 messages to c. Value = last = count"
c increment increment count      "chain: count sent to (increment's result)"

A cascade’s receiver is the receiver of the first message before the first ;.

Defining a method (browser template)

incrementBy: anInteger          "selector + arg name = method header"
    count := count + anInteger   "body; no ^ means it returns self"

Blocks & conditionals are just messages

x > 0 ifTrue: [ 'pos' ] ifFalse: [ 'neg' ]    "ifTrue:ifFalse: sent to a Boolean"
3 timesRepeat: [ Transcript show: 'hi' ]
#(1 2 3) do: [ :each | Transcript show: each printString ]

This card is the compressed form of Lesson 0001. Ask your teacher (Claude) to expand any row into practice.