Page 6 of 7

Re: filter enhancements

Posted: Sat Jul 13, 2013 11:01 pm
by monte
for those that missed that thread could you elaborate?

Re: filter enhancements

Posted: Sat Jul 13, 2013 11:21 pm
by DarScott
@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.

Re: filter enhancements

Posted: Sun Jul 14, 2013 12:19 am
by monte
It would be nice if it did...

Re: filter enhancements

Posted: Sun Jul 14, 2013 12:27 am
by DarScott
(I thought I had missed something.)

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

Re: filter enhancements

Posted: Sun Jul 14, 2013 6:02 am
by mwieder
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 & "]*"

Re: filter enhancements

Posted: Sun Jul 14, 2013 9:48 am
by Janschenkel
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.

Re: filter enhancements

Posted: Sun Jul 14, 2013 6:08 pm
by mwieder
Yes, filter-map-reduce would be a great addition, but I think the syntax is getting less xtalky.

Re: filter enhancements

Posted: Sun Jul 14, 2013 7:16 pm
by DarScott
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'.

Re: filter enhancements

Posted: Sun Jul 14, 2013 7:43 pm
by DarScott
Maybe this can be an expression:

Code: Select all

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

Re: filter enhancements

Posted: Sun Jul 14, 2013 9:20 pm
by Janschenkel
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.

Re: filter enhancements

Posted: Sun Jul 14, 2013 10:35 pm
by DarScott
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.)

Re: filter enhancements

Posted: Mon Jul 15, 2013 1:48 am
by mwieder

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?

Re: filter enhancements

Posted: Mon Jul 15, 2013 3:20 am
by monte
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"... 

Re: filter enhancements

Posted: Mon Jul 15, 2013 4:52 am
by Janschenkel
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.

Re: filter enhancements

Posted: Mon Jul 15, 2013 5:09 am
by DarScott
@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.