Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -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.
].

View file

@ -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

View file

@ -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.

View file

@ -0,0 +1,15 @@
p := Point x:10 y:20.
p addSlot:'z'. "instance specific added slot"
p z:30.
p z.
p z:40.
p inspect. "shows 3 slots"
"Point class is unaffected:"
p2 := Point x:20 y:30.
p2 z:40. -> error; Point does not implement z:
p2 inspect. "shows 2 slots"
"but we can create another instance of the enhanced point (even though its an anon class)"
p3 := p class new.
p3 x:1 y:2.
p3 z:4.
p3 inspect. "shows 3 slots"

View file

@ -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 .