filter enhancements

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, LCMark

monte
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1564
Joined: Fri Jan 13, 2012 1:47 am
Contact:

Re: filter enhancements

Post by monte » Sat Jul 13, 2013 11:01 pm

for those that missed that thread could you elaborate?
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

DarScott
Posts: 227
Joined: Fri Jul 28, 2006 12:23 am
Location: Albuquerque
Contact:

Re: filter enhancements

Post by DarScott » Sat Jul 13, 2013 11:21 pm

@monte, well, assuming @mwieder and I are talking about the same instance it is this:

Code: Select all

filter tGood with ("*" & item 1 of gCodes & "*") or ("*" & item 2 of gCodes & "*") or ("*" & item 3 of gCodes & "*")
I responded assuming that didn't really work. After the above comment, I don't really know.

monte
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1564
Joined: Fri Jan 13, 2012 1:47 am
Contact:

Re: filter enhancements

Post by monte » Sun Jul 14, 2013 12:19 am

It would be nice if it did...
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

DarScott
Posts: 227
Joined: Fri Jul 28, 2006 12:23 am
Location: Albuquerque
Contact:

Re: filter enhancements

Post by DarScott » Sun Jul 14, 2013 12:27 am

(I thought I had missed something.)

Yeah it would be nice. Maybe with 'each' like with sort.

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: filter enhancements

Post by mwieder » Sun Jul 14, 2013 6:02 am

If it worked it would save me a lot of multiple copying, but I'm not sure it's the syntax I'd choose, probably opting for something like

Code: Select all

filter tGood matching regex "*[" & item 1 to 3 of gCodes & "]*"

Janschenkel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 977
Joined: Sat Apr 08, 2006 7:47 am
Location: Aalst, Belgium
Contact:

Re: filter enhancements

Post by Janschenkel » Sun Jul 14, 2013 9:48 am

Once I get around to implementing filter-map-reduce, you could use arbitrary boolean expressions in your filter script:

Code: Select all

filter theList by item 3 of each is "foo" or item 6 of each is "bar"
filter theList by each begins with "baz" and each ends with "qux"
filter theList by MyBooleanFunction(each) into theFilteredList
I think that would allow you to convert most 'repeat for each' filtering loops.

Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: filter enhancements

Post by mwieder » Sun Jul 14, 2013 6:08 pm

Yes, filter-map-reduce would be a great addition, but I think the syntax is getting less xtalky.

DarScott
Posts: 227
Joined: Fri Jul 28, 2006 12:23 am
Location: Albuquerque
Contact:

Re: filter enhancements

Post by DarScott » Sun Jul 14, 2013 7:16 pm

I think Jan's suggestion is very xtalky. Maybe I'm missing something. I would have integrated it into a different approach for this based on cool (hopefully xtalky) syntax for application and reduction in general, but what he has is good for this limited scope. And 'each' is an established concept; we should let it earn its keep.

I'm not saying it is the best xtalky syntax. I would not have used 'by'. But it is shorter than 'keeping lines where'.

DarScott
Posts: 227
Joined: Fri Jul 28, 2006 12:23 am
Location: Albuquerque
Contact:

Re: filter enhancements

Post by DarScott » Sun Jul 14, 2013 7:43 pm

Maybe this can be an expression:

Code: Select all

get  the lines of x where (item 3 of each) = 3

Janschenkel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 977
Joined: Sat Apr 08, 2006 7:47 am
Location: Aalst, Belgium
Contact:

Re: filter enhancements

Post by Janschenkel » Sun Jul 14, 2013 9:20 pm

Heh, I'm definitely not married to my originally proposed syntax - 'by' makes sense for the 'sort' command, but not so much for 'filter'...
Just looked at the dictionary to refresh my memory, and we already have the 'mark' command which uses 'where' for its conditional clause.
So I'll probably adopt 'where' instead of 'by'.

Code: Select all

filter theList where item 3 of each is "foo" or item 6 of each is "bar"
filter theList where each begins with "baz" and each ends with "qux"
filter theList where MyBooleanFunction(each) into theFilteredList
Once I have the time to work on it, I'll open a new topic on this forum, and we can flesh out the filter-map-reduce syntax.

Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com

DarScott
Posts: 227
Joined: Fri Jul 28, 2006 12:23 am
Location: Albuquerque
Contact:

Re: filter enhancements

Post by DarScott » Sun Jul 14, 2013 10:35 pm

Hmmm. "keeping lines where" is not that long if we also have "keeping items where" and and so on.

I look forward to your bringing this up Jan when you are ready.


(I do like the idea of expressions for mapping, reducing, selecting and logical-ing over chunks but I might be the only one to use them.)

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: filter enhancements

Post by mwieder » Mon Jul 15, 2013 1:48 am

Code: Select all

    filter theList where item 3 of each is "foo" or item 6 of each is "bar"
    filter theList where each begins with "baz" and each ends with "qux"
    filter theList where MyBooleanFunction(each) into theFilteredList
I think the last example might be better with the original "by"

@Dar-
I might be the only one to use them.
I seriously doubt that :-)
This is gonna be really useful. I just have in the back of my mind the idea that there's a more "natural language" way to express this, it just isn't coming to me right now. And of course, expressing complex boolean expressions in natural language can be prone to errors., i.e.,

Code: Select all

 filter xyzzy with a and b or c or d and item 3 of e or f -- wtf?

monte
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1564
Joined: Fri Jan 13, 2012 1:47 am
Contact:

Re: filter enhancements

Post by monte » Mon Jul 15, 2013 3:20 am

Is there any reason with and without can't work?

Code: Select all

filter thelist with item 3 of each is "foo"... 
It's probably worth pointing out that with a few tweaks you've got some basic SQL like syntax...

Code: Select all

select item 1 to 3 from theList where item 3 of each is "foo"... 
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

Janschenkel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 977
Joined: Sat Apr 08, 2006 7:47 am
Location: Aalst, Belgium
Contact:

Re: filter enhancements

Post by Janschenkel » Mon Jul 15, 2013 4:52 am

monte wrote:Is there any reason with and without can't work?
Well you have to differentiate the intent somehow at the syntax level. Maybe we'll have both 'where' and 'by' as synonyms, just like the pairs 'with'/'matching' and 'without'/'not matching' - so developers can write what best fits their coding style. On the other hand, multiple ways to express the same logic always run the risk of cognitive overload and confusion for whoever needs to read the code.
But we're getting ahead of ourselves here, as it will be a few weeks before I can get into that project.

Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com

DarScott
Posts: 227
Joined: Fri Jul 28, 2006 12:23 am
Location: Albuquerque
Contact:

Re: filter enhancements

Post by DarScott » Mon Jul 15, 2013 5:09 am

@monte, I'd rather go closer to FOL than to SQL.

@mwieder, maybe it would be a good exercise to try expressing some of these in our own English style and ignoring LiveCode for a bit. It is hard for me. I keep thinking LiveCode, but you might be able to do it. My first try for filtering:

...the lines of x where each line begins with quote and each line ends with quote...
...the lines of x where each begins with quote and each ends with quote...
...the items of flyList where each item is a number...
...the words of y where character 4 of each word is "a", all as lines...
...the elements of z where each is a number and test(each)...
...the integer indexed elements of z as lines...
...the lines of x where each is among the items of y where y is a number...
...the lines of x where each is among the items of (the items of y where y is a number)...
...scrambleItems( the lines of x as items ) as lines...
...the lines of x that are not empty...
...the lines of x that begin and end with quote...
...the nonempty lines of x as integer indexed elements...
...the lines of x not in y...
...the lines of x that are not in y...
...the lines of x, call each y, such that p(y)...

Maybe some of those work.

This sounds fun but is not what Jan is thinking and might be scary for most language thinkers and implimenters.

Locked

Return to “Engine Contributors”