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

Improvements anyone?

 [1/4] from: kpeters:otaksoft at: 29-Nov-2007 20:14


Does anyone have suggestions on how to improve the function below? TIA, Kai The 'filter function below returns a result block containing only "records" having the filter criterion crit in "column" column filter: function [ cursor [block!] reclen [integer!] column [integer!] crit ] [ rec result tmp ] [ ; result: make block! length? cursor crit: to-string crit ; forskip cursor reclen [ rec: copy/part cursor reclen ; if none <> find to-string cursor/:column crit [ insert tail result rec ] ] result ] s: s: [ 100 "Jim" 45 201 "Bob" 52 325 "Will" 16 ] probe filter s 3 2 "i" ; filter for names containing letter "i"

 [2/4] from: moliad:gm:ail at: 30-Nov-2007 0:04


hi kai you might want to copy the block and use remove-each, its a very fast iterator, and expressly built for filtering. remove-each 'item copy ["a" 1 2 4 "f"] [integer? item] == ["a" "f"] using any or all in the evaluated block, is a very dense way to do multi-rule filtering remove-each 'item copy ["a" 1 2 4 "f"] [ any [ all [integer? item item > 3] all [string? item find item "a"] ] ] == [1 2 "f"] also, just adding a 'NOT in front of the 'ANY, reverses the filter, which is handy if you want to split the same incongruous data set into two pieces. -MAx On Nov 29, 2007 11:14 PM, Kai Peters <kpeters-otaksoft.com> wrote:

 [3/4] from: kpeters::otaksoft::com at: 29-Nov-2007 21:39


Thanks Max ~ I don't grasp why you use 'item "literally" - can you explain why? Kai On Fri, 30 Nov 2007 00:04:28 -0500, Maxim Olivier-Adlhoch wrote:

 [4/4] from: moliad::gmail::com at: 2-Dec-2007 14:50


cause its a typo? hehehe sorry, just put a word normally, I don't know why I put a litteral. as pekr pointed out, remove-each is one of the fastest iterators (or a couple of internal reasons). when you have filtering to do, on data which is not reused a second time, and no copy is needed, remove-each is always the fastest way to scream through a block. if you must copy the data set for eventual reuse, then some profiling is needed, and the details of the algorythm, might put parse in front, but as a rule of thumb, use remove-each when you can :-). -MAx On Nov 30, 2007 12:39 AM, Kai Peters <kpeters-otaksoft.com> wrote: