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

[REBOL] Re: list filter idom => idiot

From: greggirwin:mindspring at: 17-Sep-2002 11:17

Hi Jason, << What other rebol idioms do you recommend for filtering items listed in one block from those in another? >> EXCLUDE is good, as Scott pointed out. REMOVE-EACH is handy too, but it's only in the betas at this time. private: [%file1.r %file2.html %file3.jpeg] files: append sort read %. [%file1.r %file2.html %file3.jpeg] remove-each file files [find private file] ; now render linked list of public files foreach file files [ print rejoin [{<a href="} file {">} file {</a><br>}] ] Here's something I started tinkering with a while back, which you may find useful. Kind of a klunky interface IMO, but that's a good excercise for the student as they say. :) split: func [ {Applies each predicate to each element in blk and returns a block of blocks with items partitioned by which predicate they match. If an item doesn't match any predicate, it will be in the last block. Only handles simple args right now.} series [series!] predicates [block!] args /local match result p ][ result: copy [] loop add length? predicates 1 [append/only result copy []] repeat el series [ match: false repeat i length? predicates [ ; Have to use a temp var for the predicate here, in addition to ; the result of the predicate call. p: get predicates/:i match: p :el either block? args [args/:i][args] if match [ append result/:i :el break ] ] if not match [ append last result :el ] ] result ] ;split [1 2 3.4 5.6 7 8.9] [integer? decimal?] none ;split [1 2 3.4 5.6 7 8.9 0 100] [lesser? greater?] [3 7] ;split [1 2 3.4 5.6 7 8.9 0 100] [lesser? greater?] 3 HTH! --Gregg