AbstractObjectsAsMethod

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

AbstractObjectsAsMethod

stes
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256


It seems the runtime (VM) defines a special selector

#define SelectorRunWithIn 49

for a message  with:run:in:  

I don't know the details of the purpose of this selector,
but I think the VM supports it so that subclasses of AbstractObjectsAsMethod,
not just subclasses of CompiledMethod, can be used as methods.

As a test (this could be documented somewhere, for example on wiki.squeak.org)
consider 2 classes 'Foo' and 'Bar' :
 
AbstractObjectsAsMethod subclass: #Foo
        instanceVariableNames: ''
        classVariableNames: ''
        poolDictionaries: ''
        category: 'ObjectAsMethodTrivial'!

!Foo methodsFor: 'RuntimeSupport'!
run:aSelector with:arguments in:aReceiver
        ""
        Transcript show:'in Foo run:with:in:'.
        Transcript cr.
        ^ self! !

Object subclass: #Bar
        instanceVariableNames: ''
        classVariableNames: ''
        poolDictionaries: ''
        category: 'ObjectAsMethodTrivial'!

!Bar class methodsFor: 'class initialization'!
addFooBar
        ""
        self addSelector:#foobar withMethod:(Foo new).
        ^ self! !

Now after fileIn of the above Foo and Bar classes,
if I open a Transcript and run in a Workspace :

|p|
p _ Bar new.
Bar addFooBar.
p foobar.

will print in an open Transcript

in Foo run:with:in:

Again, I think this could/or should be documented on wiki.squeak.org,
but what happens is, I think, that if  I dynamically add a message (method)
implementation to class Bar, using addFooBar, which is installing
a method #foobar using addSelector:withMethod:, then the VM dispatched
a run:with:in message to the 'method' object, which need not be a actually,
a subclass of CompiledMethod.

Also some other selectors flushCache, selector: and methodClass: seem
necessary for this feature to work.

By subclassing AbstractObjectsAsMethod, on the other hand, it is not required
to implement flushCache, selector: and methodClass: as AbstractObjectsAsMethod
is doing that, so perhaps the intented usage is to subclass

 AbstractObjectsAsMethod

That is why in the above example I do:

 AbstractObjectsAsMethod subclass: #Foo

If this is a standard Squeak feature, it could be on the wiki.squeak.org;
I was not able to find info on it.

David Stes
 
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iQEcBAEBCAAGBQJgSfvAAAoJEAwpOKXMq1MaaGkIAKlXT+qfJcTVjMXRZwABdhFP
nTYk+yxSVCarXcoNZSDM6P6dC3xurEECF2Ypkr4zN7QvogFU/4hpe90AXWNPP26E
kmX5fJy59bxld1OlNYOX3DjTx69cL8/0QKcBHdRS6Ka012WY0Af415r9bLca6kOc
b19FsWDZe9FcXJUaHqiQRBvyhQBt3NcVwYUIXlRwHEiTPfLIXqkjPlOOTlTtezRE
B9m3u0GI0ycUcj4hMb7HpSZQOlb6ADfyz4pYXr+0js3EKxiFC6VSThPB0cJpcOTl
o7dGjS2kFwX333JJfpyztETqWjmUR6s9PLGGZe9Ki2H7LsKKi4Gy35yWs33n0tI=
=tvmw
-----END PGP SIGNATURE-----
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: AbstractObjectsAsMethod

stes
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256


When doing a search on wiki.squeak.org: search for AbstractObjectsAsMethod

it finds matches in

ListOfClassesInSqueak5dot0
ListOfClassesInSqueak5dot1
ListOfClassesInSqueak5dot2
ListOfClassesInSqueak5dot3

So AbstractObjectsAsMethod  is in there, but there is no info,
that the purpose is (I think) that subclasses provide their own version of

   run:aSelector with:arguments in:aReceiver

where the run:with:in: message is dispatched by the VM.

In the example with the class Bar where I add #foobar
using addSelector:withMethod:

aSelector is #foobar
arguments is an Array
aReceiver is then an instance of Bar

David Stes

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iQEcBAEBCAAGBQJgSf+RAAoJEAwpOKXMq1MalZUH/jaympPLw9I5nj9XWcktII+x
8L42KDIUTYROfo7+SbJ14/lx4POujxSPG7F8LYBkzNoVS+7fzA8WVZK+h1yYx6du
BdpINh5XuMtgMft/u9b/0dS56xbnk0+oKkCKLV7G6iujMl8qfPjGXy6b2MWedDuF
OOBPeIakns2JCmwOMRwWnREZt1H3xOa8WEPBW4cQZ7aSje5H9gHCBEabtkd12x1T
WJU4+JsuNTk9bUlo8w1NchfbEdAR1vrzoHlTwxlJYTn5Vt3wsKUyox9Vxfut0skf
uMpg2jhVYGSkqve39jclvhqB/Pjw0UgLeLAWCBErYK814wBYB5+8Boqx7Mq+6KI=
=8OYx
-----END PGP SIGNATURE-----
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: AbstractObjectsAsMethod

Christoph Thiede

Hi David,


I think this is already documented quite well in TestObjectsAsMethods, directly in your image. IMO this kind of documentation is also more sustainable than documentation in a far-away wiki that can deprecate and be out of sync with the rest of the code. :-)


Best,

Christoph


Von: Beginners <[hidden email]> im Auftrag von [hidden email] <[hidden email]>
Gesendet: Donnerstag, 11. März 2021 12:32:29
An: beginners
Betreff: Re: [Newbies] AbstractObjectsAsMethod
 
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256


When doing a search on wiki.squeak.org: search for AbstractObjectsAsMethod

it finds matches in

ListOfClassesInSqueak5dot0
ListOfClassesInSqueak5dot1
ListOfClassesInSqueak5dot2
ListOfClassesInSqueak5dot3

So AbstractObjectsAsMethod  is in there, but there is no info,
that the purpose is (I think) that subclasses provide their own version of

   run:aSelector with:arguments in:aReceiver

where the run:with:in: message is dispatched by the VM.

In the example with the class Bar where I add #foobar
using addSelector:withMethod:

aSelector is #foobar
arguments is an Array
aReceiver is then an instance of Bar

David Stes

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iQEcBAEBCAAGBQJgSf+RAAoJEAwpOKXMq1MalZUH/jaympPLw9I5nj9XWcktII+x
8L42KDIUTYROfo7+SbJ14/lx4POujxSPG7F8LYBkzNoVS+7fzA8WVZK+h1yYx6du
BdpINh5XuMtgMft/u9b/0dS56xbnk0+oKkCKLV7G6iujMl8qfPjGXy6b2MWedDuF
OOBPeIakns2JCmwOMRwWnREZt1H3xOa8WEPBW4cQZ7aSje5H9gHCBEabtkd12x1T
WJU4+JsuNTk9bUlo8w1NchfbEdAR1vrzoHlTwxlJYTn5Vt3wsKUyox9Vxfut0skf
uMpg2jhVYGSkqve39jclvhqB/Pjw0UgLeLAWCBErYK814wBYB5+8Boqx7Mq+6KI=
=8OYx
-----END PGP SIGNATURE-----
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Carpe Squeak!
Reply | Threaded
Open this post in threaded view
|

Re: AbstractObjectsAsMethod

David T. Lewis
Actually I think that David is right, a page on the wiki would be quite
helpful here. I do not understand the topic well enough to write that
page, but it would be great if someone can explain it.

In this case the wiki page might explain something about the background
of ObjectsAsMethods. Why was it invented, and for what might it potentially
be useful? Sometimes features like this are invented because they are
interesting and "just because we can". In other cases, there is some
bigger idea involved. I don't know which it is here, the feature is
interesting but I can't think of any useful application for it.

I also note that class TestObjectsAsMethods and its two support classes
AbstractObjectsAsMethod and ObjectsAsMethodsExample do not even have
any class comments. Nor do any of the tests have method comments. Yes,
it is possible to figure out how it works by experimenting with the
tests, but this certainly does not qualify as good in-image documentation.
Some class comments would be welcome here :-)

Dave


On Thu, Mar 11, 2021 at 11:48:01AM +0000, Thiede, Christoph wrote:

> Hi David,
>
>
> I think this is already documented quite well in TestObjectsAsMethods, directly in your image. IMO this kind of documentation is also more sustainable than documentation in a far-away wiki that can deprecate and be out of sync with the rest of the code. :-)
>
>
> Best,
>
> Christoph
>
> <http://www.hpi.de/>
> ________________________________
> Von: Beginners <[hidden email]> im Auftrag von [hidden email] <[hidden email]>
> Gesendet: Donnerstag, 11. M?rz 2021 12:32:29
> An: beginners
> Betreff: Re: [Newbies] AbstractObjectsAsMethod
>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA256
>
>
> When doing a search on wiki.squeak.org: search for AbstractObjectsAsMethod
>
> it finds matches in
>
> ListOfClassesInSqueak5dot0
> ListOfClassesInSqueak5dot1
> ListOfClassesInSqueak5dot2
> ListOfClassesInSqueak5dot3
>
> So AbstractObjectsAsMethod  is in there, but there is no info,
> that the purpose is (I think) that subclasses provide their own version of
>
>    run:aSelector with:arguments in:aReceiver
>
> where the run:with:in: message is dispatched by the VM.
>
> In the example with the class Bar where I add #foobar
> using addSelector:withMethod:
>
> aSelector is #foobar
> arguments is an Array
> aReceiver is then an instance of Bar
>
> David Stes
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v2
>
> iQEcBAEBCAAGBQJgSf+RAAoJEAwpOKXMq1MalZUH/jaympPLw9I5nj9XWcktII+x
> 8L42KDIUTYROfo7+SbJ14/lx4POujxSPG7F8LYBkzNoVS+7fzA8WVZK+h1yYx6du
> BdpINh5XuMtgMft/u9b/0dS56xbnk0+oKkCKLV7G6iujMl8qfPjGXy6b2MWedDuF
> OOBPeIakns2JCmwOMRwWnREZt1H3xOa8WEPBW4cQZ7aSje5H9gHCBEabtkd12x1T
> WJU4+JsuNTk9bUlo8w1NchfbEdAR1vrzoHlTwxlJYTn5Vt3wsKUyox9Vxfut0skf
> uMpg2jhVYGSkqve39jclvhqB/Pjw0UgLeLAWCBErYK814wBYB5+8Boqx7Mq+6KI=
> =8OYx
> -----END PGP SIGNATURE-----
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://lists.squeakfoundation.org/mailman/listinfo/beginners

> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://lists.squeakfoundation.org/mailman/listinfo/beginners

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
tty
Reply | Threaded
Open this post in threaded view
|

Re: AbstractObjectsAsMethod

tty

A semi-newbies view from the cheap seats here.

This looks like a variant of the command pattern.  

If so, that might be a useful note on the new wiki page.

cheers.


---- On Sat, 13 Mar 2021 09:47:46 -0500 David T. Lewis <[hidden email]> wrote ----

Actually I think that David is right, a page on the wiki would be quite
helpful here. I do not understand the topic well enough to write that
page, but it would be great if someone can explain it.

In this case the wiki page might explain something about the background
of ObjectsAsMethods. Why was it invented, and for what might it potentially
be useful? Sometimes features like this are invented because they are
interesting and "just because we can". In other cases, there is some
bigger idea involved. I don't know which it is here, the feature is
interesting but I can't think of any useful application for it.

I also note that class TestObjectsAsMethods and its two support classes
AbstractObjectsAsMethod and ObjectsAsMethodsExample do not even have
any class comments. Nor do any of the tests have method comments. Yes,
it is possible to figure out how it works by experimenting with the
tests, but this certainly does not qualify as good in-image documentation.
Some class comments would be welcome here :-)

Dave


On Thu, Mar 11, 2021 at 11:48:01AM +0000, Thiede, Christoph wrote:

> Hi David,
>
>
> I think this is already documented quite well in TestObjectsAsMethods, directly in your image. IMO this kind of documentation is also more sustainable than documentation in a far-away wiki that can deprecate and be out of sync with the rest of the code. :-)
>
>
> Best,
>
> Christoph
>
> <http://www.hpi.de/>
> ________________________________
> Von: Beginners <[hidden email]> im Auftrag von [hidden email] <[hidden email]>
> Gesendet: Donnerstag, 11. M?rz 2021 12:32:29
> An: beginners
> Betreff: Re: [Newbies] AbstractObjectsAsMethod
>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA256
>
>
> When doing a search on wiki.squeak.org: search for AbstractObjectsAsMethod
>
> it finds matches in
>
> ListOfClassesInSqueak5dot0
> ListOfClassesInSqueak5dot1
> ListOfClassesInSqueak5dot2
> ListOfClassesInSqueak5dot3
>
> So AbstractObjectsAsMethod is in there, but there is no info,
> that the purpose is (I think) that subclasses provide their own version of
>
> run:aSelector with:arguments in:aReceiver
>
> where the run:with:in: message is dispatched by the VM.
>
> In the example with the class Bar where I add #foobar
> using addSelector:withMethod:
>
> aSelector is #foobar
> arguments is an Array
> aReceiver is then an instance of Bar
>
> David Stes
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v2
>
> iQEcBAEBCAAGBQJgSf+RAAoJEAwpOKXMq1MalZUH/jaympPLw9I5nj9XWcktII+x
> 8L42KDIUTYROfo7+SbJ14/lx4POujxSPG7F8LYBkzNoVS+7fzA8WVZK+h1yYx6du
> BdpINh5XuMtgMft/u9b/0dS56xbnk0+oKkCKLV7G6iujMl8qfPjGXy6b2MWedDuF
> OOBPeIakns2JCmwOMRwWnREZt1H3xOa8WEPBW4cQZ7aSje5H9gHCBEabtkd12x1T
> WJU4+JsuNTk9bUlo8w1NchfbEdAR1vrzoHlTwxlJYTn5Vt3wsKUyox9Vxfut0skf
> uMpg2jhVYGSkqve39jclvhqB/Pjw0UgLeLAWCBErYK814wBYB5+8Boqx7Mq+6KI=
> =8OYx
> -----END PGP SIGNATURE-----
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://lists.squeakfoundation.org/mailman/listinfo/beginners

> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://lists.squeakfoundation.org/mailman/listinfo/beginners

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners



_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: AbstractObjectsAsMethod

stes
In reply to this post by stes
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256


When I select the method run:with:in: of the class
(AbstractObjectsAsMethods subclass) ObjectsAsMethodsExample :

and then I click in the menu on "Implementors of it" (m), I find:

Implementors of run:with:in:

ObjectsAsMethodsExample run:with:in: {as yet unclassified}
TestCoverage run:with:in: {evaluation}
WrappedBreakpoint run:with:in: {evaluation}

So I suspect the classes "TestCoverage" and "WrappedBreakpoint"
somehow also implement run:with:in

Perhaps TestCoverage in the category SUnitGUI is a reason why the feature is
there.

David Stes



-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iQEcBAEBCAAGBQJgT7ABAAoJEAwpOKXMq1MaJ4gIAK2xW25G4ScKyagy6C2XUzEj
bySA/MPqvZlvFqHixn+Z1/VeIOAJYamojV0Y8S3mymc0ACRHrunMAwCrsVqgQpBV
yPAadkHY41J2vZT1hrhJOHuRHHF35yGWSGHVir3ucFzamfBQluUWIhh5NPK+BBrK
kk//j91v8aci5bLWR4GVWmoaOytI78/3EAESKvvkT4e7+CVz4gRjsX6kfKQY3l3J
301GhMtdb905jqxoe97U4lBRyY2ZDkwpqHPNgrWwnE6SydbhIHDZeJ+qadZYmlr4
dbFsjs5m90vtl2P4+ut6frGUC6URmaKOte+NrWGJ8SaHhv385kQTW+tucZNVHCI=
=VrXK
-----END PGP SIGNATURE-----
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: AbstractObjectsAsMethod

marcel.taeumel
Hi David, hi all!

For using object-as-method, you do not need to inherit from #AbstractObjectsAsMethod. Just install an object into a class' method dictionary that implements #run:with:in:.

Method Wrappers do this:
https://github.com/hpi-swa/MethodWrappers

Here is an example for installing such objects-as-methods:
https://github.com/hpi-swa/MethodWrappers/blob/master/packages/MethodWrappers.package/MwMethodWrapper.class/instance/install.st

It uses Behavior >> #addSelectorSilently:withMethod: to modify the class' method dictionary.

Best,
Marcel

Am 15.03.2021 20:06:33 schrieb [hidden email] <[hidden email]>:

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256


When I select the method run:with:in: of the class
(AbstractObjectsAsMethods subclass) ObjectsAsMethodsExample :

and then I click in the menu on "Implementors of it" (m), I find:

Implementors of run:with:in:

ObjectsAsMethodsExample run:with:in: {as yet unclassified}
TestCoverage run:with:in: {evaluation}
WrappedBreakpoint run:with:in: {evaluation}

So I suspect the classes "TestCoverage" and "WrappedBreakpoint"
somehow also implement run:with:in

Perhaps TestCoverage in the category SUnitGUI is a reason why the feature is
there.

David Stes



-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iQEcBAEBCAAGBQJgT7ABAAoJEAwpOKXMq1MaJ4gIAK2xW25G4ScKyagy6C2XUzEj
bySA/MPqvZlvFqHixn+Z1/VeIOAJYamojV0Y8S3mymc0ACRHrunMAwCrsVqgQpBV
yPAadkHY41J2vZT1hrhJOHuRHHF35yGWSGHVir3ucFzamfBQluUWIhh5NPK+BBrK
kk//j91v8aci5bLWR4GVWmoaOytI78/3EAESKvvkT4e7+CVz4gRjsX6kfKQY3l3J
301GhMtdb905jqxoe97U4lBRyY2ZDkwpqHPNgrWwnE6SydbhIHDZeJ+qadZYmlr4
dbFsjs5m90vtl2P4+ut6frGUC6URmaKOte+NrWGJ8SaHhv385kQTW+tucZNVHCI=
=VrXK
-----END PGP SIGNATURE-----
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: AbstractObjectsAsMethod

marcel.taeumel
... and in WrappedBreakpoint >> #install, you find an other way to update a method dictionary. :-)

Best,
Marcel

Am 16.03.2021 09:24:34 schrieb Marcel Taeumel <[hidden email]>:

Hi David, hi all!

For using object-as-method, you do not need to inherit from #AbstractObjectsAsMethod. Just install an object into a class' method dictionary that implements #run:with:in:.

Method Wrappers do this:
https://github.com/hpi-swa/MethodWrappers

Here is an example for installing such objects-as-methods:
https://github.com/hpi-swa/MethodWrappers/blob/master/packages/MethodWrappers.package/MwMethodWrapper.class/instance/install.st

It uses Behavior >> #addSelectorSilently:withMethod: to modify the class' method dictionary.

Best,
Marcel

Am 15.03.2021 20:06:33 schrieb [hidden email] <[hidden email]>:

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256


When I select the method run:with:in: of the class
(AbstractObjectsAsMethods subclass) ObjectsAsMethodsExample :

and then I click in the menu on "Implementors of it" (m), I find:

Implementors of run:with:in:

ObjectsAsMethodsExample run:with:in: {as yet unclassified}
TestCoverage run:with:in: {evaluation}
WrappedBreakpoint run:with:in: {evaluation}

So I suspect the classes "TestCoverage" and "WrappedBreakpoint"
somehow also implement run:with:in

Perhaps TestCoverage in the category SUnitGUI is a reason why the feature is
there.

David Stes



-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iQEcBAEBCAAGBQJgT7ABAAoJEAwpOKXMq1MaJ4gIAK2xW25G4ScKyagy6C2XUzEj
bySA/MPqvZlvFqHixn+Z1/VeIOAJYamojV0Y8S3mymc0ACRHrunMAwCrsVqgQpBV
yPAadkHY41J2vZT1hrhJOHuRHHF35yGWSGHVir3ucFzamfBQluUWIhh5NPK+BBrK
kk//j91v8aci5bLWR4GVWmoaOytI78/3EAESKvvkT4e7+CVz4gRjsX6kfKQY3l3J
301GhMtdb905jqxoe97U4lBRyY2ZDkwpqHPNgrWwnE6SydbhIHDZeJ+qadZYmlr4
dbFsjs5m90vtl2P4+ut6frGUC6URmaKOte+NrWGJ8SaHhv385kQTW+tucZNVHCI=
=VrXK
-----END PGP SIGNATURE-----
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners