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

[REBOL] objects without overhead Re:

From: rishi:picostar at: 17-Oct-2000 23:08

Well...I thought about this a bit and I THINK I found an elegant solution. So I guess I'll respond to my own question... I think the solution to this problem is inner objects. Here is an example: myobject: make object! [ - function1: func[][..] - function2: func[][..] - . - . - make: func[var1 var2 var3][ - return make object! [ - instancevar1: var1 - instancevar2: var2 - instancevar3: var3 - - instancefunc1: function1 ;copies a reference to function1 above... - instancefunc2: function2 - ] - ] ] ;;;create instance of object coolobj: myobject/make coolobj/instancfunc1 ; all instances access same function! less overhead if many objects!!! . . . I am not sure if this would work since I have never tested it (yet). The questions in my mind are: 1. are functions copied by reference or value? if by value, this would not solve my problem 2. do inner objects have access to outer object words? for example, can 'instancefunc1 access 'function1 as shown above? I hope this works. If it does, it would be a very simple but elegant solution to my problem. It would be even more elegent when modules come around so I can keep all private words in context of myobject rather than the actual object returned...making code very clear. Rishi Previously, you ([rishi--picostar--com]) wrote: