I tried this in the script/run included here. It doesn't seem
to work when the functions are methods in an object -
or else the syntax is a little more complex. I've tried
a couple of variations of the syntax, but still get
error msgs rather than an answere one way or the
other.



Lasislav wrote:

> Actually, the functions are not replicated. Cf:
> 
> a: func [] [print "done"]
> b: :a
> same? :a :b
> 
> The functions are the same as in the former example. HTH
> 
> Ladislav


> [EMAIL PROTECTED] wrote:
> 
>  I am considering writing an app that would create several hundred or
> a few thousand copies of a single object. One way to keep track of them
> is to use an array. A script that tests this syntax is below along with
> a run which does a "print mold" on the array. It appears that the
> functions(methods) in the object are replicated for each instance
> of the object in the array. Is this true? Is this efficient? I am more
> used to OO languages like C++ where only the data fields would
> be replicated and there would be only one copy of the functions
> for all the instances of the class. Is there a better way to do this? 
> 

===== start of script

REBOL [ Title: "test05 "
        Author: " ww "
      ]

count-x:  1

myobj:  [
             x: (count-x)
             y: 5
             myfun: func [ x ] [ return x ]
             myfun2: func [ ] [ return y ]
        ]


xarr: array 5

for i 1 5 1 [ do rejoin compose ["xarr/" (i) ": (make object! myobj  ) "  ]
               count-x: count-x + 1
             ]


print "demo: show myfun exists/works"

print  join  "xarr/1/myfun : " xarr/1/myfun 7
print  join  "xarr/2/myfun : " xarr/2/myfun 7.43

print " are they the same? "

print same? :xarr/1/myfun   :xarr/2/myfun

===== end of script

===== start of run

Script started on Sat Nov 27 14:10:20 1999
l
>> do load %t05.r
demo: show myfun exists/works
xarr/1/myfun : 7
xarr/2/myfun : 7.43
 are they the same? 
** Script Error: xarr is missing its x argument.
** Where: print same? :xarr/1/myfun :xarr/2/myfun
>> q

Script done on Sat Nov 27 14:10:41 1999

===== end of run




Reply via email to