[REBOL] Re: length? pick problems
From: al:bri:xtra at: 26-Nov-2000 12:47
> repeat count x [if length? pick table-data count = 0 [remove table-data
count]]
Your problem is here-------------------------######### The '= is comparing
'count and "0" and returning false.
A better solution is:
>> table-data: map table-data func [Item [string!]] [
[ either empty? Item [exit][Item]
[ ]
== ["CREAF" "Nasdaq-NM" "$" "14.3125" "0.4375" "3.15%" "28,800" "CSCO"
Nasdaq-NM
"$" "52.6875" "2.125" "4.2%" "21,082,300" "
DELL"...
>> print mold table-data
["CREAF" "Nasdaq-NM" "$" "14.3125" "0.4375" "3.15%" "28,800" "CSCO"
Nasdaq-NM
"$" "52.6875" "2.125" "4.2%" "21,082,300" "DEL
L" "Nasdaq-NM" "$" "24.375" "1.375" "5.98%" "10,594,700" "COMS" "Nasdaq-NM"
$
"14.125" "0.125" "0.89%" "1,784,500" "SUNW" "N
asdaq-NM" "$" "84.875" "4.875" "6.09%" "10,086,900"]
I hope that helps!
Andrew Martin
ICQ: 26227169
http://members.nbci.com/AndrewMartin/
-><-
[
Rebol [
Name: 'Map
Title: "Map"
File: %"Map.r"
Home: http://members.nbci.com/AndrewMartin/Rebol/Enhancements/Map.r
Author: "Andrew Martin"
eMail: [Al--Bri--xtra--co--nz]
Date: 17/November/2000
Version: 1.5.0
History: [
1.5.0 {Removed 'throw-on-error to make it easier to track bugs
down.}
1.4.0 {Modified to have any number of arguments per function}
1.3.0 {Modified to work with series! instead of block!.}
1.2.0 {unset! results are not returned - so allowing values to be
filtered out.}
1.1.0 "Added /Only refinement."
1.0.0 "Original."
]
Enhancement: 'Map
Acknowledgements: [
"Joel Neely"
"Ladislav"
]
Purpose: {Maps or applies the function to all elements of the series.}
Example: [
Map func [n [number!]] [n * n] [1 2 3]
;== [1 4 9]
Map [1 2 3] func [n [number!]] [n * n]
;== [1 4 9]
Map [1 2 3 4 5 6] func [a] [print [a]]
;1
;2
;3
;4
;5
;6
;== []
Map [1 2 3 4 5 6] func [a b] [print [a b]]
;1 2
;3 4
;5 6
;== []
Map [1 2 3 4 5 6] func [a b c] [print [a b c]]
;1 2 3
;4 5 6
;== []
]
]
Arguments: function [f [any-function!]] [Arguments] [
Arguments: make block! 2
foreach Argument pick :f 1 [
if refinement? :Argument [
break
]
append Arguments :Argument
]
Arguments
]
Map: function [
{Maps or applies the function to all elements of the series.}
Arg1 [any-function! series!]
Arg2 [any-function! series!]
/Only "Inserts the result of the function as a series."
][
Result Results Function Series
][
any [
all [
any-function? :Arg1 series? :Arg2
(Function: :Arg1 Series: :Arg2 true)
]
all [
any-function? :Arg2 series? :Arg1
(Function: :Arg2 Series: :Arg1 true)
]
throw make error! reduce [
'script 'cannot-use rejoin [
{"} mold 'Map " " mold type? :Arg1 {"}
]
rejoin [
{"} mold type? :Arg2 {"}
]
]
]
Results: make Series length? Series
do reduce [
'foreach Arguments :Function 'Series compose [
if not unset? set/any 'Result Function (Arguments :Function) [
either only [
insert/only tail Results :Result
][
insert tail Results :Result
]
]
]
]
Results
]
]