Add all the A tasks
This commit is contained in:
parent
2dd7375f96
commit
051504d65b
1608 changed files with 18584 additions and 0 deletions
|
|
@ -0,0 +1,16 @@
|
|||
|addSlot p|
|
||||
|
||||
addSlot :=
|
||||
[:obj :slotName |
|
||||
|anonCls newObj|
|
||||
anonCls := obj class
|
||||
subclass:(obj class name,'+') asSymbol
|
||||
instanceVariableNames:slotName
|
||||
classVariableNames:''
|
||||
poolDictionaries:'' category:nil
|
||||
inEnvironment:nil.
|
||||
anonCls compile:('%1 ^ %1' bindWith:slotName).
|
||||
anonCls compile:('%1:v %1 := v' bindWith:slotName).
|
||||
newObj := anonCls cloneFrom:obj.
|
||||
obj become:newObj.
|
||||
].
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
p := Point x:10 y:20.
|
||||
addSlot value:p value:'z'.
|
||||
p z:30.
|
||||
p z.
|
||||
p z:40.
|
||||
p inspect
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
!Object methodsFor:'adding slots'!
|
||||
|
||||
addSlot: slotName
|
||||
|anonCls newObj|
|
||||
|
||||
anonCls := self class
|
||||
subclass:(self class name,'+') asSymbol
|
||||
instanceVariableNames:slotName
|
||||
classVariableNames:''
|
||||
poolDictionaries:'' category:nil
|
||||
inEnvironment:nil.
|
||||
anonCls compile:('%1 ^ %1' bindWith:slotName).
|
||||
anonCls compile:('%1:v %1 := v' bindWith:slotName).
|
||||
newObj := anonCls cloneFrom:self.
|
||||
self become:newObj.
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
p := Point x:10 y:20.
|
||||
p addSlot:'z'.
|
||||
p z:30.
|
||||
p z.
|
||||
p z:40.
|
||||
p inspect
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
Object subclass: #Monkey
|
||||
instanceVariableNames: 'aVar'
|
||||
classVariableNames: ''
|
||||
poolDictionaries: ''
|
||||
category: nil !
|
||||
|
||||
!Monkey class methodsFor: 'new instance'!
|
||||
new
|
||||
| o |
|
||||
o := super new.
|
||||
o init.
|
||||
^o
|
||||
!!
|
||||
|
||||
!Monkey methodsFor: 'init instance'!
|
||||
init
|
||||
aVar := 0
|
||||
!
|
||||
initWith: value
|
||||
aVar := value
|
||||
!!
|
||||
|
||||
!Monkey methodsFor: 'set/get the inst var(s)'!
|
||||
setVar: var
|
||||
aVar := var
|
||||
!
|
||||
getVar
|
||||
^aVar
|
||||
!!
|
||||
|
||||
|
||||
"Create a new instance"
|
||||
Smalltalk at: #aMonkey put: (Monkey new) !
|
||||
|
||||
"set the 'original' instance var to 12"
|
||||
aMonkey setVar: 12 .
|
||||
|
||||
"let's see what's inside"
|
||||
aMonkey inspect .
|
||||
|
||||
"add a new instance var"
|
||||
Monkey addInstVarName: 'x'.
|
||||
|
||||
"let's see what's inside now"
|
||||
aMonkey inspect .
|
||||
|
||||
"let us create a new method for x"
|
||||
!Monkey methodsFor: 'about x'!
|
||||
setX: val
|
||||
x := val
|
||||
!
|
||||
x
|
||||
^x
|
||||
!!
|
||||
|
||||
aMonkey setX: 10 .
|
||||
aMonkey inspect .
|
||||
(aMonkey x) printNl .
|
||||
Loading…
Add table
Add a link
Reference in a new issue