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

list filter idom => idiot

 [1/6] from: jason:cunliffe:verizon at: 17-Sep-2002 6:52


doh..well I solved my exceedingly simple problem => private: [%file1.r %file2.html %file3.jpeg] files: sort read %. public: copy [] foreach file files [ either find privatefile [print "private viewing by appointments only"] [append public file] ] ; now render linked list of public files foreach file public [ print rejoin [{<a href="} file {">} file {</a><br>}] ] What other rebol idioms do you recommend for filtering items listed in one block from those in another? thanks ./Jason

 [2/6] from: gscottjones:mchsi at: 17-Sep-2002 9:36


From: "Jason Cunliffe" ...
> What other rebol idioms do you recommend for filtering items listed in one
block
> from those in another?
Hi, Jason, Here is another approach, using the REBOL word exclude: private: copy [] append private to-file "rebol.r" append private to-file "prefs.r" files: sort read %. ;get rid of directory listings forall files [if dir? files/1 [remove files]] files: head files ;removes private files from set files: exclude files private foreach file files [ print rejoin [{<a href="} file {">} file {</a><br>}] ] --Scott Jones

 [3/6] 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

 [4/6] from: gerardcote:sympatico:ca at: 17-Sep-2002 20:05


Hi Jason, ------------------------ You wrote : -------------------------------------
> << What other rebol idioms do you recommend for filtering items listed in > one block from those in another? >>
----------------------------------------------------------------------------- I just read about the INTERSECT and DIFFERENCE words from the Core user's guide and suddenly I think this could be used to easily filter out some elements from two series as the examples suggest... I didn't work them out but seems like an alternative to look at if I presume well about their respective use... HTH! Regards, Gerard

 [5/6] from: jason:cunliffe:verizon at: 17-Sep-2002 20:42


Thanks everyone.. EXCLUDE REMOVE-EACH INTERSECT DIFFERENCE Lots to explore. I like these much better than any nested either/ifs. For some reason, whenever I use even a simple either/if (more than one level deep), I feel a little guilty/clumsy. It seems rebol has better more 'forward' moving idioms. But I forget them sometmies when I jump from soemthing like Flash Actionscript [JavaScript]. REBOL: reverse FORTH! cheers ./Jason

 [6/6] from: rebol::optushome::com::au at: 18-Sep-2002 3:46


I like these much better than any nested either/ifs.
> For some reason, whenever I use even a simple either/if (more than one
level
> deep), I feel a little guilty/clumsy. > It seems rebol has better more 'forward' moving idioms. > But I forget them sometmies when I jump from soemthing like Flash
Actionscript
> [JavaScript].
Other ways to explore for handling nested either/ifs are the use of ALL and ANY Cheers, Allen K