filter command

Ben Rubinstein benr_mc at cogapp.com
Wed Apr 10 12:20:01 EDT 2002


on 10/4/02 4:53 PM, Dave Cragg at dcragg at lacscentre.co.uk wrote:

> At 4:05 pm +0200 10/4/02, yves COPPE wrote:
>> Hello,
>> 
>> 
>> I have two flds. There are list flds.
>> I'd like to put in a variable the lines which are common to the two flds
>> 
> The following function should do what you want. I'm sure there are other ways.
> [snip... code putting both lists into arrays...]

As Dave says, there are a lot of ways to solve most problems in Rev.  My
$0.02 to add is just

a) two of the great enhancements in MC/Rev are the 'repeat for each' loops,
and arrays.  I wrote something recently doing a variation on this theme
(merging two tab-delimited lists based on identity of certain fields).  I
initally wrote it stepping through one list, searching in the other... When
I rewrote it making arrays (using 'for each' loops to build them as Dave
indicated) and then doing the comparisons on that, the speed reward (on
files with 20-50,000 rows) was incredible - from several minutes to < 2
seconds.

b) depending on your exact needs, you may be able to do this using the
'split' command to make arrays out of your lists, the 'intersect' command to
reduce one array to the common elements, and the 'combine' command to put it
all back together.  Eg (nb from memory, not tested, may not work):

    function commonLines pList1, pList2
        split pList1 using return
        split pList2 using return
        intersect pList1 with pList2
        combine pList1 using return
        return pList1
    end commonLines
 
  Ben Rubinstein               |  Email: benr_mc at cogapp.com
  Cognitive Applications Ltd   |  Phone: +44 (0)1273-821600
  http://www.cogapp.com        |  Fax  : +44 (0)1273-728866






More information about the use-livecode mailing list