"Lecture 20, CSE341, Winter 2006" "Introduction to Smalltalk -- Workspace based on fall 2004 demo" 4. Transcript show: 4. x _ true. y := 5. z := 1 [ y > 1 ] whileTrue: [z := z * y. y:= y - 1]. z str := 'hi mom'. str at: 4 str at: 4 put: $t. str at: 4 str class "str at: 4 put: 34" "str at: 'huh' put: $x" "str at: 123 put: $x" 5 negated. 4 + 9. 3 raisedTo: 4 "nil negated" " 'hi' negated " " [3] negated" th := [x+y]. x:=4. y_3. th value. [3] value negated factHelp := [:x :acc | [x > 1] whileTrue: [acc _ acc * x. x _ x - 1]. acc]. fact := [:x | factHelp value: x value: 1]. fact2 := [:x | factHelp valueWithArguments: {x. 1}]. (fact value: 5) + (fact2 value: 4) factcheck := [:x | x > 0 ifTrue: [fact value: x] ifFalse: [self error: 'neg arg']] "(factcheck value: 5) + (factcheck value: -3)" Object subclass: #MyPoint instanceVariableNames: 'x y' classVariableNames: '' poolDictionaries: '' category: 'lec20' pt := MyPoint new "pt x" "nobody actually defines methods this way" MyPoint compile: 'x ^x'. MyPoint compile: 'x: a x _a' pt x. pt x: 17. pt x.