From: Mathieu Bouchard Date: 2005-04-24T23:25:57+09:00 Subject: Re: [ANN] Article: Seeing Metaclasses Clearly ---1077017559-192036790-1114352737=:32332 Content-Type: MULTIPART/MIXED; BOUNDARY="-1077017559-192036790-1114352737=:32332" This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. ---1077017559-192036790-1114352737=:32332 Content-Type: TEXT/PLAIN; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: QUOTED-PRINTABLE On Sun, 24 Apr 2005, gabriele renzi wrote: > Mathieu Bouchard ha scritto: >> On Thu, 21 Apr 2005, gabriele renzi wrote: >> Because of backwards-compatibility with C++/Java/Perl/Python programmers= =2E >> Most backwards-compatibility issues occur wrt the _programmers_ and not = so=20 >> much wrt the _programmes_. > Python programmers for sure can define singleton methods directly in a ob= ject=20 > without singleton classes, I avow I don't know enough Python for that. > I guess perl folks too, since an object is mostly=20 > an hash (I may be wrong, not really good at perl). No: in Perl, a hash can contain anonymous subs (that is like Ruby procs),= =20 but the method lookup is a different thing. For example, suppose you have= =20 a variable $x holding a pointer to an object that is made out of a hash.=20 Then calling a proc that is an instance variable will look like: $x->{hello}(); and that is also valid syntax for calling an anonymous sub in any Perl=20 hash, even if it doesn't have a class attached to it. But that mechanism=20 does not support inheritance at all. What is called a method-call in Perl= =20 is: $x->hello; where hello is a _named_ sub in the package that has been assigned to the= =20 $x hash using the bless() builtin. In Ruby, this is the same difference as between those two expressions: x.foo x.instance_eval{@foo}[] and clearly the latter isn't calling a method foo in x, and can't perform= =20 anything inheritance-related either. > Actually, only Java's anonymous classes seem somewhat similar to singleto= n=20 > ones. They are not. They are a special case of inner classes, and inner classes= =20 blend the concepts of class, delegation, and closure, all together, but=20 nothing in Java is singleton. But still I am curious: could you please=20 provide a snippet in which you emulate singleton behaviour using Java's=20 anonymous classes? ,-o---------o---------o---------o-. ,----. | | The Diagram is the Program (TM) | | ,-o----------------------------o-. `-o-----------------------------o-' | | Mathieu Bouchard (Montr=E9al QC)= | | |---' | http://artengine.ca/matju | | | `-o------------------------------' ---1077017559-192036790-1114352737=:32332-- ---1077017559-192036790-1114352737=:32332--