Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search

[REBOL] Re: REBOL : Pure OOP project ?

From: chrismorency:videotron:ca at: 7-Apr-2002 23:19

Hi Etienne, Thanks for your reply... hope it generates interest. It's late, source code provided from memory. First answer to your question, I did some basic tests and so far, it's working quite well... but no, I have no statistics/memeory consumption. The idea is like a big game of ping-pong... simply send a message to an instance and the instance will send itself to the class with the message as long as it does not get it's return value and the return value is sent until it gets to the original sender ;) The current implementation is pretty simple and allows for the classic Metaclass(class class)-Class-Object. Basically it's a set of functions implemented within one object which implements two methods (new and subclass) and provides a lot of basic mechanics of objects like super, etc... Subclasses are created like this foo/subclass #subclass-name [ instance-variables [i] instance-methods [ get-i: method [] [] [return self/i] set-i: method [aValue] [] [self/i: aValue] ] class-variables [c] class-methods [ get-c: method [] [] [return self/c] set-c: method [aValue] [] [self/c: aValue] ] ] Basically, the processor generate three objects implementing the class : subclass-name: make object! [ "class instance" c: 5 "the real c" class: make object! [ "metaclass instance" interface: make object! [ "class class" super: foo/class/interface {as object!} c: none "the c use for instanciation" get-c: func [self] [return self/c] set-c: func [self aValue] [self/c: aValue] subclass: func [self class-name source] [return super/subclass self class-name source] new: func [self] [return super/new self] [...] ] [...] ] get-c: func [] [return class/interface/get-c] set-c: func [aValue] [return class/interface/set-c self aValue] subclass: func [class-name source] [return class/interface/subclass self class-name source] new: func [] [return class/interface/new self] [...] interface: make object! [ "instance class" i: none "the i use for instanciation" super: foo/interface {as object!} get-i: func [self] [return self/i] set-i: func [self aValue] [self/i: aValue] [...] ] ] Instances are declared with this a: subclass-name/new == make object! [ "instance" i: 5 "the real i" class: subclass-name {as object!} get-i: func [] [return class/interface/get-i self] set-i: func [aValue] [return class/interface/set-i self aValue] [...] ] note: for all instances, variables are set to none at start Of course with all the inter-relations between object... forget about the current probe function ;) I wrote several implementation of this model, and the current one is quite simple, short and understandable by most rebol newcomers. The only problem I have with this implementation is that methods are still functions and not objects ! and datatypes are still datatypes not objects ! --- The new implementation I was thinking about was to completely rewrite my implementation within a Object/Behavior/Class/Metaclass hiearchy and provides a cleaner library ! But instance methods are still functions, instance datatypes are not objects! -- The best implementation would be to have a class for all rebol datatypes, including functions... which would have inherited methods allowing us to provide basic mechanics to objects like : aString: String/new aString/set "ok" aString/get == "ok" value? aString/value == string! aString/value == "ok" In this case, the string! datatype is embedded in a instance of String class. aMethod: Method/new aMethod/specs: [] aMethod/source: [] aMethod/do Methods of a class could be in a collection (instance of Collection with block! as it's value datatype!), you could add, remove, rename methods... since the instances would provide a link to the methods collection of their class. As soon as you change a method in the class, all instances would be affected. Etc. Now this is a tricky part, and I cannot do that alone... Oh and just for those still reading... have fun with the following... Maybe it's a trail to some solutions, but I have not grokked it yet ;) a: make object! [ name: "a" this: func [] [return self] ] b: make a [ name: "b" ] a/self: b probe a/this probe b/this Hmm all of this works for Core... Best, Chris