Re: [Oorexx-devel] object, class, metaclass... Big picture ?

2011-08-08 Thread Rony G. Flatscher
Hi Jean-Louis,

it seems that Rick is currently not online, so I try to give some shots,
hoping they may help a little bit.

[One problem in OO is the terminology, which sometimes comes into ones
way (instead of clarifying concepts, sometimes they obfuscate them,
unfortunately). There are quite a few synonyms, like object ==
instance == value etc. or class == type etc.]

On 08.08.2011 10:23, Jean-Louis Faucher wrote:
 I try to understand the underlying model for object, class, metaclass
 (source excerpt at the end of the mail). Not easy...

ooRexx has been quite influenced by Smalltalk, so some of the concepts
are directly from there.

In general there are no class methods!
(This means among other things that all methods are instance methods!)
:)

---

* There is simply a class that allows one to define methods and
  attributes the methods of a class can have direct access to.
  o A 'method is a function/procedure that is only available
for instances of the class in which the methods are defined.
* An object is just an instance of a class. The object possesses
  the functionality/behaviour of the methods of its class.
* There is a class hierarchy which is used when method resolution
  takes place with the concept that all methods (not attributes!) of
  all the superclasses (shortest path to root class) get inherited.
  (This is also the area where scope becomes important w.r.t. method
  resolution, but also access to attributes, i.e. concurrency issues
  and the like.)
  o The class hierarchy allows an object to have more methods
(functionality/behaviour) than defined in its own class, by
means of inheritance.
* The root of a class hierarchy is usually calld Object, which is
  a class, as it defines methods. As all other classes in ooRexx are
  derived directly (by default) or indirectly from this root class,
  its methods (functionality/behaviour) is inherited by all other
  classes (and its instances)!

---

In dynamic languages the class definitions (the name, the methods) are
represented in objects as well. The class used for creating objects that
keep the definition of a class in ooRexx (and many other languages) is
called Class. As instances of this class describe the structure and
behaviour of individual classes the term metaclass is used for it. So
the ooRexx class Class is the metaclass of ooRexx. Of course, if one
subclasses Class it inherits all abilities of Class and as such
keeps on being able to maintain the definition of classes. An instance
of Class or one of its subclasses (hence of any metaclass) is called
class object.

The instance methods of metaclasses (i.e. class objects) are called
class methods, indicating that these methods belong to the class object.

---

When ooRexx starts up the class hierarchy is created in native code and
from the image. I.e. all ooRexx supplied classes build (and are
represented in) the ooRexx class hierarchy in the form of class objects.
Each of these class objects maintains e.g. the name of the class and the
methods, instances of this class should get assigned to at creation time
(which is done in the 'new' method of Class).

At runtime one can access these class objects with their environment
symbol, which is the name of the class preceeded by a dot, e.g.:
.object, .class, .array and the like.

---

One speciality (and very powerful feature) of ooRexx is its ability to
add/remove methods from instances (one-off-objects)! Cf. e.g. the
Object's methods setMethod and unsetMethod, but also the Class
method enhanced to create instances of a class which get additional
methods (hence one-off).

It is also possible to change the set of methods instances of a class
get assigned to, when they get created. Cf. the Class methods
method, methods, define and delete, which allow to maintain the
methods instances of a class should get assigned to at the time they got
created.

Note: the method instanceMethod and instanceMethods in the root
class Object allow one to fetch the actual instance method(s) of an
object (ie. also from one-off objects).

---

Finally ad methods of a class object: all methods of a class object are
instance methods, sometimes dubbed class methods, because they are
the instance methods of a metclass/class object. A class object is just
a normal ooRexx object and as such it is possible to add/remove instance
methods to/from it!

When an ooRexx class defines methods with the subkeyword class then
these methods will be added to the class object (as instance methods of
the class object).

---

Hope that helps clarify a few of your questions.

Ad ooRexx native code and implementation, this is something that
probably Rick is the only one who can answer at the moment.

---rony



 I can't find a suitable definition for the ??? below.

 Extracted from rexxref :

 5.1.1
 The Object class is the root of the class hierarchy.
 The instance methods 

Re: [Oorexx-devel] object, class, metaclass... Big picture ?

2011-08-08 Thread Rony G. Flatscher
Hi Jean-Louis,

overlooked the send question: in ooRexx the defined methods and the
messages (represented by the tilde/twiddle/~) are represented in their
own ooRexx classes.

So if in a Rexx program the ~ is encountered a message object (an
instance of the class Message) is created. However, the creation of a
message does not yet cause that message to be dispatched to the object.
In order to dispatch a message object (which actually carries out the
message) one has to send it either the mssage send or start.

* Using the send method causes the execution to halt until the
  message has been carried out in full and allows one to fetch
  directly a result value, if any.
* Using the start method cuases the execution to go on, the
  message is carried out concurrently and returns an object, which
  can be interrogated for the status of the asynchroneous execution
  of the started message. Eventually, when the asynchroneous message
  finished, one can learn that and even fetch the result.

Cf. the reference documentation of the class Message.

HTH,

---rony


On 08.08.2011 11:39, Rony G. Flatscher wrote:
 Hi Jean-Louis,

 it seems that Rick is currently not online, so I try to give some
 shots, hoping they may help a little bit.

 [One problem in OO is the terminology, which sometimes comes into ones
 way (instead of clarifying concepts, sometimes they obfuscate them,
 unfortunately). There are quite a few synonyms, like object ==
 instance == value etc. or class == type etc.]

 On 08.08.2011 10:23, Jean-Louis Faucher wrote:
 I try to understand the underlying model for object, class, metaclass
 (source excerpt at the end of the mail). Not easy...

 ooRexx has been quite influenced by Smalltalk, so some of the concepts
 are directly from there.

 In general there are no class methods!
 (This means among other things that all methods are instance methods!)
 :)

 ---

 * There is simply a class that allows one to define methods and
   attributes the methods of a class can have direct access to.
   o A 'method is a function/procedure that is only available
 for instances of the class in which the methods are defined.
 * An object is just an instance of a class. The object possesses
   the functionality/behaviour of the methods of its class.
 * There is a class hierarchy which is used when method
   resolution takes place with the concept that all methods (not
   attributes!) of all the superclasses (shortest path to root
   class) get inherited. (This is also the area where scope becomes
   important w.r.t. method resolution, but also access to
   attributes, i.e. concurrency issues and the like.)
   o The class hierarchy allows an object to have more methods
 (functionality/behaviour) than defined in its own class,
 by means of inheritance.
 * The root of a class hierarchy is usually calld Object, which
   is a class, as it defines methods. As all other classes in
   ooRexx are derived directly (by default) or indirectly from this
   root class, its methods (functionality/behaviour) is inherited
   by all other classes (and its instances)!

 ---

 In dynamic languages the class definitions (the name, the methods) are
 represented in objects as well. The class used for creating objects
 that keep the definition of a class in ooRexx (and many other
 languages) is called Class. As instances of this class describe the
 structure and behaviour of individual classes the term metaclass is
 used for it. So the ooRexx class Class is the metaclass of ooRexx.
 Of course, if one subclasses Class it inherits all abilities of
 Class and as such keeps on being able to maintain the definition of
 classes. An instance of Class or one of its subclasses (hence of any
 metaclass) is called class object.

 The instance methods of metaclasses (i.e. class objects) are called
 class methods, indicating that these methods belong to the class object.

 ---

 When ooRexx starts up the class hierarchy is created in native code
 and from the image. I.e. all ooRexx supplied classes build (and are
 represented in) the ooRexx class hierarchy in the form of class
 objects. Each of these class objects maintains e.g. the name of the
 class and the methods, instances of this class should get assigned to
 at creation time (which is done in the 'new' method of Class).

 At runtime one can access these class objects with their environment
 symbol, which is the name of the class preceeded by a dot, e.g.:
 .object, .class, .array and the like.

 ---

 One speciality (and very powerful feature) of ooRexx is its ability to
 add/remove methods from instances (one-off-objects)! Cf. e.g. the
 Object's methods setMethod and unsetMethod, but also the Class
 method enhanced to create instances of a class which get additional
 methods (hence one-off).

 It is also possible to change the set of methods instances of a 

Re: [Oorexx-devel] object, class, metaclass... Big picture ?

2011-08-08 Thread Jean-Louis Faucher
Thanks a lot Rony !

About ~send, I was focusing on the search order for method selection, and I
found the answer in rexxref 4.2.5.
There is no reference to metaclass there, so I assume that the methods of a
metaclass are not visible from an object.

Honestly, I can't say it's still very clear for the distinction
class/metaclass. I thought that a metaclass was the class of a class, but
this is not the case in the internal model.

(All the details in the attached file...)

RexxClass is a RexxObject. As such, it inherits the attribute 'behaviour'
which is used for : ~class, ~instanceMethod, ~instanceMethods, ~setMethod,
~unsetMethod
Though this behaviour, I can get the class of a RexxClass.

But RexxClass has also an attribute 'metaClass' which is an array of
RexxClass.

The other attributes for which it's not clear are :
scopes
classMethodDictionary (~!DEFINE_CLASS_METHOD)
metaClassMethodDictionary
metaClassScopes

Jean-Louis

2011/8/8 Rony G. Flatscher rony.flatsc...@wu-wien.ac.at

 **
 Hi Jean-Louis,

 overlooked the send question: in ooRexx the defined methods and the
 messages (represented by the tilde/twiddle/~) are represented in their own
 ooRexx classes.

 So if in a Rexx program the ~ is encountered a message object (an
 instance of the class Message) is created. However, the creation of a
 message does not yet cause that message to be dispatched to the object. In
 order to dispatch a message object (which actually carries out the message)
 one has to send it either the mssage send or start.

- Using the send method causes the execution to halt until the
message has been carried out in full and allows one to fetch directly a
result value, if any.
- Using the start method cuases the execution to go on, the message
is carried out concurrently and returns an object, which can be 
 interrogated
for the status of the asynchroneous execution of the started message.
Eventually, when the asynchroneous message finished, one can learn that and
even fetch the result.

 Cf. the reference documentation of the class Message.

 HTH,

 ---rony



 On 08.08.2011 11:39, Rony G. Flatscher wrote:

 Hi Jean-Louis,

 it seems that Rick is currently not online, so I try to give some shots,
 hoping they may help a little bit.

 [One problem in OO is the terminology, which sometimes comes into ones way
 (instead of clarifying concepts, sometimes they obfuscate them,
 unfortunately). There are quite a few synonyms, like object == instance
 == value etc. or class == type etc.]

 On 08.08.2011 10:23, Jean-Louis Faucher wrote:

 I try to understand the underlying model for object, class, metaclass
 (source excerpt at the end of the mail). Not easy...


 ooRexx has been quite influenced by Smalltalk, so some of the concepts are
 directly from there.

 In general there are no class methods!
 (This means among other things that all methods are instance methods!)
 :)

 ---

- There is simply a class that allows one to define methods and
attributes the methods of a class can have direct access to.
 - A 'method is a function/procedure that is only available for
   instances of the class in which the methods are defined.
- An object is just an instance of a class. The object possesses the
functionality/behaviour of the methods of its class.
 - There is a class hierarchy which is used when method resolution
takes place with the concept that all methods (not attributes!) of all the
superclasses (shortest path to root class) get inherited. (This is also the
area where scope becomes important w.r.t. method resolution, but also 
 access
to attributes, i.e. concurrency issues and the like.)
 - The class hierarchy allows an object to have more methods
   (functionality/behaviour) than defined in its own class, by means of
   inheritance.
- The root of a class hierarchy is usually calld Object, which is a
class, as it defines methods. As all other classes in ooRexx are derived
directly (by default) or indirectly from this root class, its methods
(functionality/behaviour) is inherited by all other classes (and its
instances)!

 ---

 In dynamic languages the class definitions (the name, the methods) are
 represented in objects as well. The class used for creating objects that
 keep the definition of a class in ooRexx (and many other languages) is
 called Class. As instances of this class describe the structure and
 behaviour of individual classes the term metaclass is used for it. So the
 ooRexx class Class is the metaclass of ooRexx. Of course, if one
 subclasses Class it inherits all abilities of Class and as such keeps on
 being able to maintain the definition of classes. An instance of Class or
 one of its subclasses (hence of any metaclass) is called class object.

 The instance methods of metaclasses (i.e. class objects) are called
 class methods, indicating that these methods belong to the class object.

 ---

 When ooRexx 

Re: [Oorexx-devel] object, class, metaclass... Big picture ?

2011-08-08 Thread Rony G. Flatscher
Hi Jean-Louis,

On 08.08.2011 14:40, Jean-Louis Faucher wrote:
 About ~send, I was focusing on the search order for method selection,
 and I found the answer in rexxref 4.2.5.
 There is no reference to metaclass there, so I assume that the methods
 of a metaclass are not visible from an object.
No, they are not!
(Unlike in C++ or Java or the like.)

If one needs to get at the class methods in ooRexx one first needs to
get at the class object (which created the object in question) by
sending the message class to the object in question. Then you can send
the names of the class methods to the class object that the message
class returned. (Again, the class object is just a plain object, so
all rules about objects apply.)

 Honestly, I can't say it's still very clear for the distinction
 class/metaclass. I thought that a metaclass was the class of a class,
 but this is not the case in the internal model.
This depends on your definition of class of a class, class and
metaclass, for which you seem to expect a distinction to be present.
There is none in ooRexx.

A metaclass is a plain class, i.e. it allows one to define methods that
are regarded to belong together to serve some purpose.

The term meta just points at the usage of a particular class, usually
named Class: this class allows one to define, maintain and interrogate
the methods of classes at runtime. But the mechanics (allowing to define
methods and sending messages) are the same as for any other class: one
can create instances, send the names of existing methods, etc. The
metaclass also has a method defined to create an instance/object/value
of the class (possessing all methods that were defined at object
creation time and which can be retrieved from the metaclass with the
message methods) and after initialization returns it: the method new.

Maybe a different application/point-of-view: every time an ooRexx
program is processed the ::class-directive will cause the runtime system
to create an instance of Class assigning that instance (a class
object) the name found with the class directive. Then, for each
::method-directive an instance of the class Method is created by the
found name, which also stores the Rexx code; that method object is then
added to the class object collection of methods that should be
assigned to objects it creates, using the class object method
define. In the case that a ::method-directive has the subkeyword
class that method is added directly to the class object instead
using the Object's method setMethod.

(The major distraction, I think, stems from the metaphysically sounding
name metaclass, as if something special, secret is allotted to it.)

The speciality of the class named Class is simply: it allows for
maintaining the name of an ooRexx class, define/delete methods that
instances of an ooRexx class should be assigned to an object, when it
gets created. That's it.

(Maybe, if you state what you think a class of a class is/should be
about, then we could discuss those concepts/expectations in more detail.)

---

Ad implementation details/rationales/structures/mechanics, again, only
Rick can explain them.
 (All the details in the attached file...)

 RexxClass is a RexxObject. As such, it inherits the attribute
 'behaviour' which is used for : ~class, ~instanceMethod,
 ~instanceMethods, ~setMethod, ~unsetMethod
 Though this behaviour, I can get the class of a RexxClass.
Yes, these are available by inheritance, they are not locally defined
in the class object for RexxClass!

 But RexxClass has also an attribute 'metaClass' which is an array of
 RexxClass.
metaClass is an instance method of the class object, defined in
RexxClass (along with e.g. define, delete. enhanced, new,
superclasses, subclasses, etc.).

Not sure why it is backed by an array in the implementation (Rick would
know, as he implemented it that way).

 The other attributes for which it's not clear are :
 scopes
A scope generally defines the visibility of variables, labels. In the
context of ooRexx it also defines the visibility of routines and
classes, e.g. routines and classes are always seen/accessible in the
program that defined them. Public routines and classes become visible
once the program was called/required that defined them.

In the context of methods there is one important item in addition:
access to attributes! Usually all methods that are defined for a class
share the same scope, i.e. if they define attributes (using the
EXPOSE-statement as the first instruction) then they are shared/visible
among all methods. Accessing attributes in parallel running/executing
methods would incur the classic problems, hence access to attributes are
guarded in ooRexx by default.

Now, it is possible in ooRexx to define methods in a program that are
not assignable to a specific class, because the method directives
preceed class-directives. Such floating methods get collected by the
interpreter and from the defining program one can access them via the
.methods environment