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

[REBOL] Re: copy with object words and values

From: ryanc:iesco-dms at: 13-Sep-2001 15:18

Gregg Irwin wrote:
> Ingo Hohmann wrote a couple nifty functions for retrieving the words and > values from an object. In his routines, he uses copy when returning the > data. > > ; Ingo Hohmann > values-of: func [ > "Returns block of object word values next to self directive" > object[object!] "Object words of which its values should be returned" > ][ > copy next second object > ] > > Q. Should I even bother worrying about efficiency? Should I just use copy, > as Ingo does, to be on the safe side or can I safely return the data without > using copy? I played around a bit and it doesn't appear that the object data > is at risk of modification, via the result, even without copy. I'm very > likely missing something though.
Copying anything really large is slowish, like a block of 20000 words or so, and should be avoided without reason. But in my view, with small portions of data, I think about it from a desired functionality perspective. Sometimes a copy is prefered, sometimes you want to work with the whole original. When writing function "libraries", often it is good to return the original, so as the programmer can decide whether a copy is warranted. On the other hand, the above code represents an instance where you want to use 'copy, reminiscent of copying the contents section from a book and excluding the first heading.
> > Q. If there is a difference, and I add a /copy refinement to the routine, is > there a way to "inline" copy so I don't have to have two separate blocks > that are identical except for the copy call? > > ; Gregg Irwin > values-of: func [ > "Returns block of object word values next to self directive" > object[object!] "Object words of which its values should be returned" > /copy "Use the copy refinement if you want a copy of the data" > ][ > either copy [copy next second object][next second object] > ] >
First you have defined 'Copy to mean something else in the body of your function. No problem though, it just has to be account for by refering to the definition of copy in system/words. You probably wont like the "inline" version as much, but here it is: do either copy [get in system/words 'copy][none] next second object This modification to what you have should work: either copy [system/words/copy next second object][next second object] But personally I would just use copy in all of them, leaving the refinement out. --Ryan
> Thanks! > > --Gregg > > -- > To unsubscribe from this list, please send an email to > [rebol-request--rebol--com] with "unsubscribe" in the > subject, without the quotes.
-- Ryan Cole Programmer Analyst www.iesco-dms.com 707-468-5400