[REBOL] Re: Block/array manipulation
From: joel:neely:fedex at: 15-Oct-2001 17:43
Hi, Mat,
Mat Bettinson wrote:
...
> Let's take a block of stuff;
>
> Stuff: make block! ["fire" "water" "air" "water" "water" "air"]
>
...
> 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.
>
Given ...
>> stuff: ["fire" "water" "air" "water" "water" "air"]
== ["fire" "water" "air" "water" "water" "air"]
... the non-duplicated version can be computed by ...
>> unique stuff
== ["fire" "water" "air"]
... and the counting version can be computed by ...
stuffstats: func [b [block!] /local result where] [
result: copy []
foreach item b [
either found? where: find result item [
change next where 1 + second where
][
append result reduce [item 1]
]
]
result
]
... as in ...
>> stuffstats stuff
== ["fire" 1 "water" 3 "air" 2]
-jn-
--
This sentence contradicts itself -- no actually it doesn't.
-- Doug Hofstadter
joel<dot>neely<at>fedex<dot>com