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

[REBOL] Re: Exclude Problems

From: joel:neely:fedex at: 28-Sep-2001 1:52

Hi, Ammon, and all, I've been way busy with a pending s/w release, so haven't been keeping up with this thread very well, but... Ammon Cooke wrote:
> Sorry, I forgot to fully omptimize that code here is a lot > smaller version: > > excl-only: func [ > "This is the Exclude function that doesn't exclude duplicates" > block1 "The original block" > block2 "The block to be 'excluded'" > ][ > tmp-block: copy block1 > repeat val block2 [remove find tmp-block val] > either not none? tmp-block[ > return head tmp-block > ][ > return tmp-block > ] > ] >
I'd suggest making TMP-BLOCK a /LOCAL to prevent contaminating the global namespace. I'm not clear on why the following wouldn't be a valid solution. Am I missing some subtlety? remove-all: func [source [block!] targets [block!] /local result] [ result: copy source foreach target targets [ remove find result target ] result ]
>> remove-all [1 2 3 4 5 6 7 8 9] [2 4 6 8]
== [1 3 5 7 9]
>> remove-all [9 8 7 6 5 4 3 2 1] [2 4 6 8]
== [9 7 5 3 1]
>> remove-all [1 9 2 8 3 7 4 5 6] [0 2 4 6 8]
== [1 9 3 7 5]
>> remove-all [1 9 2 8 3 7 4 5 6] []
== [1 9 2 8 3 7 4 5 6]
>> remove-all [1 2 2 3 3 3 4 4 4 4 5 5 5 5 5 6 6 6 6 6 6] [1 2 3 4 5 6 7 8 9]
== [2 3 3 4 4 4 5 5 5 5 6 6 6 6 6]
>> remove-all [] [1]
== []
>> remove-all [2] [1]
== [2]
>> remove-all [2] []
== [2]
>> remove-all [2] [2 2 2 2]
== []
>> remove-all [1 2 2 3 3 3 4 4 4 4 5 5 5 5 5 6 6 6 6 6 6] [9 8 7 6 5 4 3 2 1]
== [2 3 3 4 4 4 5 5 5 5 6 6 6 6 6] I can't think of any more obvious test scenarios at the moment, but would be happy to hear of anything I've overlooked. -jn- -- That so few now dare to be eccentric marks the chief danger of the time. -- John Stuart Mill (1806-1873) FIX&PUNCTUATION&joel&dot&neely&at&fedex&dot&com