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

[REBOL] Fwd: Re: Why should I copy ?

From: moliad:gma:il at: 5-Oct-2009 16:10

I had replied 2 weeks ago, but it seems my post never got to the mailing list, here it is... again. On Thu, Sep 24, 2009 at 12:22 PM, Sunanda <dhsunanda-gmail.com> wrote:
> Lesson: use COPY. it associates the word 'b with a fresh [] each time > > =====
......
> > > This behaviour can take a while to get used to ;) >
I just want to point out that this isn't' a bug, its a feature by design. =A0All rebol series are mutable, so they aren't copied each time they are assigned to a variable, like in most other languages, python for example. this means a big boost in assignment speed and it also means that series can be shared amongst many references by default, another thing which allows many optimizations. =A0Most other languages will create independent versions of series every time they are assigned, and sharing them becomes difficult. remember my function hack example, it doesn't copy the block created as storage for the function value... this is an example of how this can be used as the feature it is. this being said, there are some variants of function! creation code out there which creates a new independent context each time the function is called, but that is slow and may cause memory leaks in some use cases... better just to use copy all the time, this way its explicit and you realize you have full control. -MAx