filter enhancements

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, LCMark

phaworth
Posts: 592
Joined: Thu Jun 11, 2009 9:51 pm

Re: filter enhancements

Post by phaworth » Sat May 25, 2013 5:09 pm

monte wrote:While we are pondering on filter it would be nice to consider arrays:

Code: Select all

filter [keys|elements of] <container> [ not ] matching [ pattern ] <pattern>
Great idea!
Pete

phaworth
Posts: 592
Joined: Thu Jun 11, 2009 9:51 pm

Re: filter enhancements

Post by phaworth » Sat May 25, 2013 5:23 pm

Folks,
Sorry to be thick but I'm still not getting sure why we need the "items" keyword.

Let's say tVar contains:

abc,123,def
abc,12345,xyz

filter items of tVar with "123" returns line 1 and filter items of tVar with "123*" returns both lines, right? But filter tVar with "*123" and filter tVar with "*123*" achieves the same result, doesn't it?

Maybe there's other use cases I'm not thinking of but "items" seems like it's just a convenience rather than serving a useful purpose.

Hopefully someone will enlighten me!

Pete

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 May 26, 2013 10:49 am

FYI: I'vs submitted a pull request for the fix that filter should honour the lineDelimiter property.

Cheers,

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

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 May 26, 2013 11:04 am

Support for filtering 'items' aims for consistency with the 'sort' command; looking at the 'sort' command I'm slightly confused about its output.
I always though that sort items meant that each line would be sorted separately, but that doesn't appear to be the case; in fact, I got strange results when sorting items in a multiline list.
Maybe we should discuss here how we expect 'filter items' to work. And leave 'sort items' to a separate but related discussion.

Base principle: 'item' chunk type < 'line' chunk type

Assuming we have a variable with the following data:

Code: Select all

foo,bar
baz,qux
And the following command:

Code: Select all

filter items of theList with "b*"
My interpretation would be that the output is:

Code: Select all

bar
baz
In other words, filter handles each line separately, and filters the items within.

Does that make sense?

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

phaworth
Posts: 592
Joined: Thu Jun 11, 2009 9:51 pm

Re: filter enhancements

Post by phaworth » Sun May 26, 2013 5:14 pm

Ah OK, I see where my confusion was - it's not the filtering end of things, it's the output format. I've never used the sort command in conjunction with items but it may cause confusion if sort items works differently than filter items.

So, if the list being filtered was:

Code: Select all

foo,bar,bad
baz,qux
...would you expect the output from your filter to be:

Code: Select all

bar
bad
baz
...or

Code: Select all

bar,bad
baz

Pete

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 May 26, 2013 6:39 pm

@phaworth
My aim is to have consistent meaning, so I would indeed expect:

Code: Select all

bar,bad
baz
(thus preserving the line structure)

Having said that, it seems that 'sort items' doesn't work that way at the moment.
It merely swaps out the lineDelimiter for the itemDelimiter, ignoring the concept of item being 'smaller than' a line in chunk terms.

Maybe someone at the run rev team can clarify the intention?
Then at least we can implement a 'filter items' command consistent with 'sort items' semantics.

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

phaworth
Posts: 592
Joined: Thu Jun 11, 2009 9:51 pm

Re: filter enhancements

Post by phaworth » Sun May 26, 2013 8:17 pm

Just tried "sort items" on:

Code: Select all

foo,bar,bad
baz,qut
The result was:

Code: Select all

bad
baz,bar,foo,qut
I can't figure out what the intent of that result is. Maybe "sort items" is broken?

Pete

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 May 26, 2013 9:06 pm

@phaworth
Yah, that's what threw me off when I did a similar test: 'sort items' appears to merely use the itemDelimiter instead of the lineDelimiter and promptly ignore the chunk hierarchy.
I don't think that's what it was meant to do, but changing it now would be a behavioural change which RunRev isn't too eager to introduce.
So I won't code the 'filter items' option until we get some clarification..

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

BvG
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1236
Joined: Sat Apr 08, 2006 1:10 pm
Location: Zurich
Contact:

Re: filter enhancements

Post by BvG » Sun May 26, 2013 10:12 pm

sort items ignores lines. just as sort lines ignores words. If you want to sort stuff that contains lines by item, it's your job to make sure that you only sort within those lines, not the engines. You specified items, and that's what you get :)

Similar, if you filter by items, it's not the engine's job to care wether you're using lines or not. So sorting a multi-line item list will be confusing (and only usefull in very rare corner cases), but sorting a list of items will work just fine.

At least that's what I'd expect.
Various teststacks and stuff:
http://bjoernke.com

Chat with other RunRev developers:
chat.freenode.net:6666 #livecode

phaworth
Posts: 592
Joined: Thu Jun 11, 2009 9:51 pm

Re: filter enhancements

Post by phaworth » Sun May 26, 2013 11:04 pm

BvG wrote:sort items ignores lines. just as sort lines ignores words. If you want to sort stuff that contains lines by item, it's your job to make sure that you only sort within those lines, not the engines. You specified items, and that's what you get :)

Similar, if you filter by items, it's not the engine's job to care wether you're using lines or not. So sorting a multi-line item list will be confusing (and only usefull in very rare corner cases), but sorting a list of items will work just fine.

At least that's what I'd expect.
OK, I understand now, thanks Bjornke. I redid the test with just one line in the variable and ti worked as expected with the items in the correct sorted order.

So I guess filter would work by returning just the items that qualified. So filtering "foo,bar,bad" with "b*" would return "bad,bar". Nice.

Pete

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 May 27, 2013 4:18 am

Hmm... I don't think I've ever used sort items on a multi-line container. My guess is the intention of sort items is for single lines containers. For multi-line containers we probably want:

Code: Select all

filter lines of theList with "b*" by chunkExpression of each
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

phaworth
Posts: 592
Joined: Thu Jun 11, 2009 9:51 pm

Re: filter enhancements

Post by phaworth » Mon May 27, 2013 5:03 am

monte wrote:Hmm... I don't think I've ever used sort items on a multi-line container. My guess is the intention of sort items is for single lines containers. For multi-line containers we probably want:

Code: Select all

filter lines of theList with "b*" by chunkExpression of each
Yep, that's pretty much it, but I think that's destined for phase II.

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 May 27, 2013 7:40 pm

Once we get around to the FIlterMapReduce phase, you could script something like:

Code: Select all

filter theList by item 2 of each begins with "b"
filter lines of theList by MyFilterFunction(each)
But that's food for a separate discussion - I first wanted to get some smaller items out of the way :-)

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

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 » Tue May 28, 2013 12:43 am

Ah... ok, serves me right for skim reading ;-)
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

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 » Tue May 28, 2013 6:37 pm

I've just gotten back into town now, and I'm a bit jetlagged in addition to coming into the discussion late.
In general I like the way this is going: fix the filter syntax first, then start making the syntax consistent across other commands, then expand on the syntax.

I *would*, however, like to take to extrapolation to array syntax into a separate thread and separate pull requests, because I think there's a lot of work to do on arrays and a lot of pitfalls along the way. Dealing with arrays of a single dimension looks easy enough by expanding the current syntax, but gets very sticky when going to multiple dimensions. And I'd like to avoid going down a path now that would have to be reverted.

Locked

Return to “Engine Contributors”