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

[REBOL] Re: Newbie Q: Search and delete from a Block

From: christophe:coussement:mil:be at: 8-Oct-2002 9:19

hi: you've to work in two times: 1. find the word 2. remove it from the block We can thus use the function "find" (to get a definition of it, type ? find in the console). If found, "Find" will return the word followed by the following words, either none if not found:
>> find ["hello" "there" "this" "is" "an" "Example"] "this"
== ["this" "is" "an" "Example"]
>>
We have then to remove the first element of this block, by using the function "remove":
>> remove ["this" "is" "an" "Example"]
== ["is" "an" "Example"]
>>
Because REBOL is the champion of the oneliners, we can write:
>> remove find ["hello" "there" "this" "is" "an" "Example"] "this"
== ["is" "an" "Example"]
>>
Ok, but now we cannot see what's before "is", and we should put it at the head of the block... so we have to address it:
>> my-block: ["hello" "there" "this" "is" "an" "Example"]
== ["hello" "there" "this" "is" "an" "Example"]
>> remove find my-block "this"
== ["is" "an" "Example"]
>> my-block
== ["hello" "there" "is" "an" "Example"]
>>
Or put the pointer of the block to the head of it:
>> head remove find ["hello" "there" "this" "is" "an" "Example"] "this"
== ["hello" "there" "is" "an" "Example"]
>>
Hope this helps ! ==christophe