32. Expressions and Messages - Solution

This exercise is about reading and understanding Pharo expressions, and differentiating between different types of messages and receivers.

Note that in the expressions you will be asked to read and executed, you can assume that the implementation of methods generally corresponds to what their message names imply (i.e., 2 + 2 = 4).

In addition, most of the expressions we use in the exercises are expressions that you can execute in Pharo, so do not hesitate.

32.0.1. Exercise: Literal objects

What kind of object does the following literal expressions refer to?

32.0.1.1. Exercise:
'Hello, Dave'

Solution.

	a string
32.0.1.2. Exercise:
1.3

Solution.

	a float
32.0.1.3. Exercise:
#node1

Solution.

	a symbol (unique string)
32.0.1.4. Exercise:
#(2 33 4)

Solution.

	an array
32.0.1.5. Exercise:
[ :each | each scale: 1.5 ]

Solution.

	a block (lexical closure)
32.0.1.6. Exercise:
$A 

Solution.

	a character
32.0.1.7. Exercise:
true

Solution.

	a boolean
32.0.1.8. Exercise:
1

Solution.

	a smallinteger

32.1. Exercise: Messages

For each of the expressions below, fill in the answers:

  • What is the receiver object?
  • What is the message selector?
  • What is/are the argument (s)?
  • What is the result returned by this expression execution?
32.1.0.1. Exercise:
3 + 4

Solution.

	receiver: 3
	selector: +
	argument: 4
32.1.0.2. Exercise:
Date today

Solution.

	receiver: Date
	selector: today
	argument: none
32.1.0.3. Exercise:
anArray at: 1 put: 'hello'

Solution.

	receiver: anArray
	selector: at:put:
	argument: 1 and 'hello'
32.1.0.4. Exercise:
anArray at: i 

Solution.

	receiver: anArray
	selector: at:
	argument: i
32.1.0.5. Exercise:
#(2 33 -4 67) collect: [ :each | each abs ]

Solution.

	receiver: #(2 33 -4 67) 
	selector: collect:
	argument:  [ :each | each abs ]
32.1.0.6. Exercise:
25 @ 50

Solution.

	receiver: 25
	selector: @
	argument: 50
32.1.0.7. Exercise:
SmallInteger maxVal

Solution.

	receiver: SmallInteger
	selector: maxVal
	argument: none
32.1.0.8. Exercise:
#(a b c d e f) includesAll: #(f d b)

Solution.

	receiver: #(a b c d e f)
	selector: includesAll:
	argument: #(f d b)
32.1.0.9. Exercise:
true | false

Solution.

	receiver: true
	selector: | 
	argument: false
32.1.0.10. Exercise:
Point selectors

Solution.

	receiver: Point
	selector: selectors
	argument: 

32.1.1. Exercise: Scope

32.1.1.1. Exercise:
  • What can one assume about a variable named Transferator?

Transferator is a global variable: either a class, a global variable or a class variable.

Solution.

32.1.1.2. Exercise:
  • What can one assume about a variable named rectangle?

Solution. rectangle is a local variable: either a temporary, an instance variable, or a method argument.