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

[REBOL] Re: How to remove words from objects?

From: luke:marmaladefoo at: 13-Jan-2004 18:25

Dear all thanks everyone for your contributions! I have in the meantime implemented my own approach which works for me (similar to the ones suggested - see below) using the "long way round" of reconstructing the object. Its not very pretty (since it involves a "do" on a dynamically built string) but it works for me, as do most of your helpful suggestions. I dont understand Gregg what you mean when you say the context of an object isnt dynamic. It probably goes beyond my current level of understanding of how REBOL works. But if so, then how does that explain why can I do this (but not reverse the action): ;---create object obj: make object [a: 1] ;---add a new word to the object obj: make obj [b: 2]
> L> I'm trying to dynamically add and remove words from an > L> object...I know I could dynamically reconstruct it from scratch, > L> but that is not very elegant. There must be a better way... > > Not really. The issue lies in the fact that the context of an object > isn't dynamic; you can't add or remove things. The global context in > REBOL is the only special case of a dynamic context I believe. > > You can get tricky and work around it, by including a block in your > object and using that as kind of a sub-context--because blocks are > resizable. I think Ladislav or Joel posted a dynamic object example > here at one time. I didn't find one on REBOL.org in a quick search, > maybe somebody submit one if they have it handy. >
This is the way I did it: object-remove-word: func [object word /local obj-result obj-copy-string action] [ obj-copy-string: copy "" obj-result: none foreach w next first object [ if not (w = word) [ value: object/:w append obj-copy-string rejoin [ " " :w ": " mold :value newline ] ] ] action: rejoin ["make object! [" obj-copy-string "]" ] obj-result: do action :obj-result ] All the best - Luke __________________________________________ Various gadgets widgets, links and chat http://www.marmaladefoo.com __________________________________________<