View this PageEdit this PageAttachments to this PageHistory of this PageHomeRecent ChangesSearch the SwikiHelp Guide
Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007

CoWeb Assignment 2 (6/14)

Tracing Code (1 pt)
1 + 2 3 - 4 factorial
Ans: -15
a := #(1 2 3 4 5)
Ans: #(1 2 3 4 5)
a select: [:i | i odd]
Ans: #(1 3 5)
b := a
Ans: #(1 2 3 4 5)
a := a reversed
Ans: #(5 4 3 2 1)
b collect: [:i | i i]
Ans: #(1 4 9 16 25)
a perform: #at: withArguments: #(4)
Ans: 2

Message Passing (1 pt)
while loop in Squeak:
[aBooleanTest] whileTrue: ["do stuff"].
Here the object is aBooleanTest, the message is whileTrue, and the argument is "do stuff".
for loop in Squeak:
1 to 10 do: [ :i | "do stuff"].
Here the object is 1, the messages are to and do, and the arguments are 10 and "do stuff".
if/then/else in Squeak:
[aBooleanTest] ifTrue: ["do this"] ifFalse: ["do that"]
Here the object is aBooleanTest, the messages are ifTrue and ifFalse, and the arguments are "do this" and "do that".