[REBOL] Problem with 'collect?
From: andrew::martin::colenso::school::nz at: 13-Aug-2003 16:21
With this script:
probe foreach Row [[A 1 B 2] [A 11 B 12]] collect [
reform selects Row [A B]
]
I get this result:
[11 12 "11 12"]
I want to get this:
["1 2" "11 12"]
I using these functions:
Collect: function [
{Collects the results of block evaluations.}
Block [block!] "The block to 'do."
/Only "Inserts the result as a series."
/Full "Don't ignore none! values."
/Initial Results [series! datatype!] "Specifies the type of
the result."
] [
Break Result
] [
Break: func [
"Breaks out of the 'Collect."
/Return "Forces the loop function to return a Value."
Value [any-type!]
] [
system/words/break/return either Return [
Value
] [
Results
]
]
Results: any [
all [
datatype? Results
make Results 0
]
Results
copy []
]
compose/deep [
if not any [
unset? set/any 'Result do [(bind Block 'Break)]
(pick [[none? :Result] []] not Full)
] [
(pick [insert insert/only] not Only) tail
Results :Result
Results
]
Results
]
]
Selects: function [
"Repeatedly finds a value in the series and returns the value or
series after it."
Series [series! port!]
Values [block!]
/Part "Limits the search to a given length or position."
Range [number! series! port!]
/Only "Treats a series value as a single value."
/Case "Characters are case-sensitive."
/Any "Enables the * and ? wildcards."
/With "Allows custom wildcards."
Wild [string!] {Specifies alternates for "*" and "?".}
/Skip "Treat the series as records of fixed size."
] [
Body
] [
Body: reduce [
foreach Refinement first :Selects collect/initial [
if equal? /local Refinement [
break
]
all [
refinement? Refinement
get bind Refinement: to word! Refinement
'Body
Refinement
]
] to path! 'Select
'Series 'Value
]
all [
Part
insert/only tail Body Range
]
all [
With
insert/only tail Body Wild
]
foreach Value Values collect Body
]
I feel that I've got something wrong in 'Collect, as it looks like the
value attached to 'Results gets muddled up between the various uses of
'Collect. Can anyone point out what I've got wrong?
Thanks!
Andrew J Martin
Attendance Officer &
Information Systems Trouble Shooter
Colenso High School
Arnold Street, Napier.
Tel: 64-6-8310180 ext 826
Fax: 64-6-8336759
http://colenso.net/scripts/Wiki.r?AJM
http://www.colenso.school.nz/
DISCLAIMER: Colenso High School and its Board of Trustees is not responsible (or legally
liable) for materials distributed to or acquired from user e-mail accounts. You can report
any
misuse of an e-mail account to our ICT Manager and the complaint will be investigated.
(Misuse can come in many forms, but can be viewed as any material sent/received that
indicate or suggest pornography, unethical or illegal solicitation, racism, sexism, inappropriate
language and/or other issues described in our Acceptable Use Policy.)
All outgoing messages are certified virus-free by McAfee GroupShield Exchange 5.10.285.0
Phone: +64 6 843 5095 or Fax: +64 6 833 6759 or E-mail: [postmaster--colenso--school--nz]