Smalltalk
Un article de MonWiki.
- "My move to Smalltalk wasn’t motivated by any particular language feature, but by what I saw as a generally richer environment and set of libraries and a deeper, more experienced community."
- "There’s a wealth of knowledge and experience in the communities around “dead” languages like Smalltalk, Lisp, and Forth, and it always saddens me to see so many mainstream developers taking years to make mistakes and discoveries they could have read about in an afternoon of browsing old papers or a few mailing list archives."
- -Avi Bryant, creator of Seaside.
Sommaire |
[modifier]
Bouts de Code
[modifier]
Factory
Utilisation du message subclassResponsibility
.
Object subclass: #Application clientMethod document := self documentClass new. documentClass self subclassResponsibility Application subclass: #MyApplication documentClass ^ MyDocument
[modifier]
Proxy Pattern
Utilisation du message doesNotUnderstand
.
on: anObject ^super new target: anObject doesNotUnderstand: aMessage ^target perform: aMessage selector withArguments: aMessage arguments | wrapper | wrapper := Proxy on: Transcript. wrapper open. wrapper show: 'Hi mom'.
[modifier]
Combinaisons
Voir aussi : Lua#Combinaisons
Exemple (Squeak) :
Object subclass: #Combi instanceVariableNames: 'set depth current' Combi>>combine: aSet withDepth: aDepth depth := aDepth. set := aSet. current := Array new: aDepth. self startRecursion. Combi>>startRecursion self recurseAtLevel: 1. Combi>>recurseAtLevel: i depth = i ifTrue: [self endRecursion. ^nil]. set do: [:currentElement | current at: i put: currentElement. self recurseAtLevel: i+1]. Combi>>endRecursion set do: [:last | current at: depth put: last. current do: [:each | Transcript show: each]. Transcript cr].
Combi new combine: #( $x 7 '+' ) withDepth: 2. xx x7 x+ 7x 77 7+ +x +7 ++
[modifier]
Permutations
Object subclass: #Permutation instanceVariableNames: 'set' permute: aSet set := aSet. self recurseAtLevel: 1. recurseAtLevel: level self print. level <= set size ifTrue: [set size-1 to: level by: -1 do: [:i | i+1 to: set size do: [:j | set swap: i with: j. self recurseAtLevel: i+1]. self rotateLeftStartingAt: i]]. rotateLeftStartingAt: start | tmp | tmp := set at: start. start to: set size-1 do: [:i | set at:i put: (set at: i+1)]. set at: set size put: tmp. print set do: [:each | Transcript show: each] separatedBy: [Transcript show: ' ']. Transcript cr.
Permutation new permute: #( $x 7 '+'). x + 7 7 x + 7 + x + x 7 + 7 x
[modifier]
Sauvegardes automatiques
Squeak.
À faire : ranger dans une classe, refactoriser, ajoûter un widget Morphic.
[[| newName | (Delay forMilliseconds: 1 * 60 * 1000) wait. newName _ 'SqueakAutoBackup'. newName isNil ifTrue: [^ self]. Mutex new critical: [(SourceFiles at: 2) ifNotNil: [SmalltalkImage current closeSourceFiles; "so copying the changes file will always work" saveChangesInFileNamed: (SmalltalkImage current fullNameForChangesNamed: newName)]. SmalltalkImage current saveImageInFileNamed: (SmalltalkImage current fullNameForImageNamed: newName)]] repeat] fork.
[modifier]