A short introduction to Smalltalk during Bar Camp Hanoi 2009. I use some slides of Alexandre Bergel for this presentation.
I you want to more information about Smalltalk in Vietnam, you can contact me.
18. A typical method in the class Point
Method name Argument Comment
<= aPoint
! quot;Answer whether the receiver is neither
! below nor to the right of aPoint.quot;
! ^ x <= aPoint x and: [y <= aPoint y]
Return Block
Binary message
Instance variable Keyword message
(2@3) <= (5@6) true
19. Statements and cascades
Temporary variables
Statement
| p pen |
p := 100@100.
pen := Pen new.
pen up.
pen goto: p; down; goto: p+p
Cascade
20. Control structures
Every control structure is realized by message sends
4 timesRepeat: [Beeper beep]
max: aNumber
! ^ self < aNumber
! ! ifTrue: [aNumber]
! ! ifFalse: [self]
21. Control structures
Every control structure is realized by message sends
4 timesRepeat: [Beeper beep]
Boolean
ifTrue:ifFalse:
max: aNumber True False
ifTrue:ifFalse: ifTrue:ifFalse:
! ^ self < aNumber
! ! ifTrue: [aNumber]
! ! ifFalse: [self]
ifTrue: t ifFalse: f ifTrue: t ifFalse: f
^ t value ^ f value
22. Creating classes
Send a message to a class (!)
Number subclass: #Complex
! instanceVariableNames: 'real imaginary'
! classVariableNames: ''
! poolDictionaries: ''
! category: 'ComplexNumbers'