[REBOL] Re: Block/array manipulation
From: jelinem1:nationwide at: 15-Oct-2001 14:55
; I think you forgot the 'not in your test:
;-------------------------------------------------------
Stuff: make block! ["fire" "water" "air" "water" "water" "air"]
foundstuff: make block! []
forall stuff [
if not found? find foundstuff (pick stuff 1) [
append foundstuff (pick stuff 1)
]
]
;-------------------------------------------------------
; Not sure in what form you want to the counts to be, so I've created a
second array whose entries correspond with the foundstuff array:
;-------------------------------------------------------
Stuff: make block! ["fire" "water" "air" "water" "water" "air"]
foundstuff: make block! []
countstuff: make block! []
forall stuff [
either not found? find foundstuff (pick stuff 1) [
append foundstuff (pick stuff 1)
append countstuff 1
][
pos: index? find foundstuff (pick stuff 1)
count-here: at countstuff pos
count-here/1: 1 + count-here/1
]
]
;-------------------------------------------------------
[Michael Jelinek]
Mat Bettinson <[mat--b--codeplay--com]>
Sent by: [rebol-bounce--rebol--com]
10/15/01 10:17 AM
Please respond to rebol-list
T
To: Jason Cunliffe <[rebol-list--rebol--com]>
cc:
bcc:
Subject: [REBOL] Block/array manipulation
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
]
]
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. :)
Regards,
Mat Bettinson
Codeplay
Tel: +44 (0)20 7482 3382
140-142 Kentish Town Rd, London, NW1 9QB
http://www.codeplay.com