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

length? pick problems

 [1/5] from: vache::bluejellybean::com at: 25-Nov-2000 15:21


REBOL [] 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" "DELL" "" "" "" "Nasdaq-NM" "" "" "" "$" "24.375" "" "" "" "1.375" "" "" "" "5.98%" "" "" "" "10,594,700" "COMS" "" "" "" "Nasdaq-NM" "" "" "" "$" "14.125" "" "" "" "0.125" "" "" "" "0.89%" "" "" "" "1,784,500" "SUNW" "" "" "" "Nasdaq-NM" "" "" "" "$" "84.875" "" "" "" "4.875" "" "" "" "6.09%" "" "" "" "10,086,900"] x: length? table-data count: 1 repeat count x [if length? pick table-data count = 0 [remove table-data count]] print table-data halt --- The goal is to loop through the block, and remove all the "" (emptey) values. However, I get an error on (length? pick table-data) Any ideas? Thanks in advanced fellow rebolers :] Vache

 [2/5] 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 ] ]

 [3/5] from: larry:ecotope at: 25-Nov-2000 16:31


Hi Vache Here is one short way to do what you want, by making use of a second block.
>> new-data: []
== []
>> foreach item table-data [if item <> "" [append new-data 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"... There are problems with using remove and other series mutators in loops because it is changing the length of the series and the position of the current index of the series while the loop is executing. The test in the loop could also be written in other ways: if (length? item) > 0 if not empty? item HTH -Larry ----- Original Message ----- From: Vache <[Vache--bluejellybean--com]> To: <[rebol-list--rebol--com]> Sent: Saturday, November 25, 2000 3:21 PM Subject: [REBOL] length? pick problems
> REBOL [] > > 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" DELL "" "" "" "Nasdaq-NM" "" "" "" "$" "24.375" "" "" "" "1.375" "" "" "" 5.98% "" "" "" "10,594,700" "COMS" "" "" "" "Nasdaq-NM" "" "" "" "$" 14.125 "" "" "" "0.125" "" "" "" "0.89%" "" "" "" "1,784,500" "SUNW" "" "" "Nasdaq-NM" "" "" "" "$" "84.875" "" "" "" "4.875" "" "" "" "6.09%" "" "" "10,086,900"]

 [4/5] from: riachtchenko:docutec at: 27-Nov-2000 12:25


Hi Andrew, i sure did't get it, since on NT adn rebol 2.31 i became:
>> table-data: ["CREAF" "" "" "" "Nasdaq-NM" "" "" "" "$"]
== ["CREAF" "" "" "" "Nasdaq-NM" "" "" "" "$"]
>> table-data: map table-data func [Item [string!]] [
[ either empty? Item [exit][Item]] ** Script Error: map has no value. ** Where: table-data: map table-data func [Item [string!]] ? Appreciate Sascha. Andrew Martin wrote:

 [5/5] from: vache:bluejellybean at: 27-Nov-2000 12:21


You need to include do %map.h at the start of your .r file. Also, thanks to everyone who helped :] I figured out how to get it to function properly. Thanks again! --- riachtchenko <[riachtchenko--docutec--de]>