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

[REBOL] Re: Block/array manipulation

From: carl:cybercraft at: 16-Oct-2001 8:54

On 16-Oct-01, Mat Bettinson wrote:
> Folks, > Here's a simple thing which I've needed to do quite a bit of, but > couldn't quite figure out how you'd do it in Rebol so tended to do > things the long way. > Let's take a block of stuff; > Stuff: make block! ["fire" "water" "air" "water" "water" "air"] > Now the object of the excersize is to to build block with all of the > unique values. That bit is easy; > foundstuff: make block! [] > foreach bitofstuff stuff [ > if found? find foundstuff bitofstuff [ > append foundstuff bitofstuff > ] > ]
Hmmm. A quick test of that didn't work for me. However, there's a word to do that. It's called 'unique. (: ...
>> unique stuff
== ["fire" "water" "air"]
> After this, all of the unique values are loaded into the > 'foundstuff' block. > The question is, say I wanted to do this but count each instance of > the words as they are subsequently found? IE I could somehow tell > that water was found 3 times and air was found twice. > This is where my rudimentary grasp of Rebol fails me. :)
Check out the related words to 'unique in the Core Guide. 'difference and such. A mix of them might give you what you want. (Sory - running late for work at the moment. :)
> Regards, > Mat Bettinson > Codeplay > Tel: +44 (0)20 7482 3382 > 140-142 Kentish Town Rd, London, NW1 9QB > http://www.codeplay.com
-- Carl Read