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

John Cook

One more year to go at Tech.

Coweb Assignment 2:


Tracing Code (1 Point)

1 + 2 * 3 - 4 factorial    
-15

a := #(1 2 3 4 5)
#(1 2 3 4 5)

a select: [:i | i odd]
#(1 3 5)

b := a
#(1 2 3 4 5)

a := a reverse
#(5 4 3 2 1)

b collect: [:i | i i]
#(1 4 9 16 25)

a perform: #at: withArguments: #(4)
2

Refactoring (1 point)

REFACTORING ANSWER

Coweb Assignment 3:


History of OO (1 point)


Virtual Machines (1 point)


This is an instance method called score from the Simon Game
score
	| myLabel contents |
	contents:= game score asString.
	myLabel := StringMorph new.
	myLabel color: Color white.
	myLabel contents: contents.
	^ myLabel.

Here is what it looks like in Bytecode

33 <01> pushRcvr: 1
34 send: score
35 send: asString
36 <69> popIntoTemp: 1
37 <42> pushLit: StringMorph
38 send: new
39 <68> popIntoTemp: 0
40 <10> pushTemp: 0
41 <45> pushLit: Color
42 send: white
43 send: color:
44 <87> pop
45 <10> pushTemp: 0
46 <11> pushTemp: 1
47 send: contents:
48 <87> pop
49 <10> pushTemp: 0
50 <7C> returnTop


Programming (1 Point)

This is an instance method placed in the String class
contractTo: aNumber
    | retString startCharNum endCharNum temp |
    (self size < aNumber) ifTrue: [^self]
        ifFalse: [aNumber <= 3 ifTrue: [^'...']
            ifFalse:[temp:= (aNumber - 3).
                     startCharNum:= (temp // 2) + (temp \\ 2).
                     endCharNum:= (self size) - (temp // 2) + 1.
                     retString:= ''.
                     1 to: startCharNum do: [ :i | retString:= retString asString, ((self at: i) asString)].
                     retString:= retString, '...'.
                     endCharNum to: (self size) do: [:j | retString:= retString asString, ((self at: j) asString)].
                     ^retString.]].


Links to this Page