Oops, that should be..
| array lookupClosure performClosure |
lookupClosure := [].
lookupClosure := [:cls :selector |
������ (cls == nil)
������ ������ ifTrue: [Warning signal: ('method lookup failure: ', selector)].
������ cls methodDictionary
������ ������ at: selector
������ ������ ifPresent: [:meth | meth]
������ ������ ifAbsent: [lookupClosure value: cls superclass value: selector]].
performClosure := [ :receiver :selector :args |
������ (lookupClosure value: receiver class value: selector)
������ ������ valueWithReceiver: receiver arguments: args ].
array := { 1 }.
performClosure value: array value: #at:put: value: {1. 'Hello, world'}.
array inspect.
and a little block cleanup:
| array lookupClosure performClosure |
lookupClosure := [].
lookupClosure := [:cls :selector |
������ (cls == nil)
������ ������ ifTrue: [Warning signal: ('method lookup failure: ', selector)].
������ cls methodDictionary
������ ������ at: selector
������ ������ ifPresent: [:meth | meth]
������ ������ ifAbsent: [lookupClosure value: cls superclass value: selector]].
performClosure := [ :receiver :args |
������ (lookupClosure value: array class value: #at:put:)
������ ������ valueWithReceiver: array arguments: args ].
array := { 1 }.
performClosure value: array value: {1. 'Hello, world'}.
array inspect.
Charlie
On 10/16/2016 9:54 AM, Charlie Robbats wrote:
Here's a little change to get your #perform:withArguments: implemented.
| array lookupClosure method |
array := { 1 }.
lookupClosure := [].
lookupClosure := [:cls :selector |
������ (cls == nil)
�������������� ifTrue: [Warning signal: ('method lookup failure: ', selector)].
������ cls methodDictionary
�������������� at: selector
"�������������� ifPresent: [:meth | Smalltalk tools browser openOnMethod: meth]"
�������������� ifPresent: [:meth | meth]
�������������� ifAbsent: [lookupClosure value: cls superclass value: selector]].
method := lookupClosure value: Array value: #at:put:.
method valueWithReceiver: array arguments: {1. 'Hello, world'}.
array
On 10/16/2016 9:32 AM, Ben Coman wrote:
On Sun, Oct 16, 2016 at 9:11 PM, Charlie Robbats
<charlie.robbats@gmail.com> wrote:
Here, Dmitry, try this code in playground...maybe helps you understandNice example.�� Slightly improved...
| lookupClosure |
lookupClosure := [].
lookupClosure := [:cls :selector |
�������� (cls == nil)
���������������� ifTrue: [Warning signal: ('selector lookup failure: ', selector)].
�������� (cls methodDictionary
���������������� at: selector
���������������� ifAbsent: [nil])
������������������������ ifNil: [lookupClosure value: cls superclass value: selector]
������������������������ ifNotNil: [:meth | Smalltalk tools browser openOnMethod: meth]].
lookupClosure value: Array value: #at:put:.
| lookupClosure |
lookupClosure := [].
lookupClosure := [:cls :selector |
�������� (cls == nil)
���������������� ifTrue: [Warning signal: ('selector lookup failure: ', selector)].
�������� cls methodDictionary
���������������� at: selector
���������������� ifPresent: [:meth | Smalltalk tools browser openOnMethod: meth]
���������������� ifAbsent: [lookupClosure value: cls superclass value: selector]].
lookupClosure value: Array value: #at:put:.
cheers -ben