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

[REBOL] Re: objects without overhead

From: rishi:picostar at: 20-Oct-2000 11:38

thanks for all the replies...
> Just define a "parent" object containing all of your functions, then create > your "used" objects by cloning this object. The "used" objects then won't > include the functions, but as the "parent" object is the prototype for the > "used" objects, then you can still use your functions through these objects. > > Example (not tested): > > parent: make object! [ > func1: func [a] [print a] > func2: func [a b] [print [a b]] > ] > > child1: make parent [ > var1: "This is a variable in a child object" > c-func1: func [a] [func1 join a var1] > ] > > child2: make parent [ > var2: "This is another variable in another child object" > c-func2: func [a b] [func2 var2 join a b] > ] > > Well, I guess you get the idea.
hmmm... I could have sworn that cloned objects actually copy everything in the object cloned. I guess I was wrong. Still, this doesn't solve my problem. The data in the cloned object cannot be accessed from the functions defined in the parents object. Anyway, I did find 2 solutions to my problem. The solution I chose was to break up my object into one small one (that will be instantiated many times) and one big one that will manipulate the many small objects. The other solution is to pass 'self to an outside funcion as shown (pay attention to get-puzzle function): ;not tested..but I bet it works as is ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; CODE BEGINS HERE state: make object! [ new: func [ puzzle [block!] ][ return make object! [ puz: copy reduce puzzle get-puzzle: :get_puzz self ] ] get_puzz: func [obj] [return copy obj/puz] ] ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;: TEST CODE ; comment { test-obj: state/new [1 2 3 4 0 5 6 7 8] print test-obj/get-puzzle ; } ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; CODE ENDS HERE Rishi