[PonyORM-list] Algebra of sets

Alexander Kozlovsky alexander.kozlovsky at gmail.com
Fri Oct 25 11:51:10 UTC 2013


Hi Vsevolod,

After the evaluating of the generator the only this item remains available
> for the following operations. So, filtering for example, the returned
> sequence we may use only the item value in a filter expression:
>
> >>> filter(lambda x:x[0]==2,[(v,k) for k in d for v in d[k]])
> [(2, 'a')]
>
>
> The same rule should be appied IMHO to the lambda-filter expression which
> is used to filter the query: the only item returned in the query result may
> be used. This particular item is an only lambda parameter of the
> lambda-filter, so we are free to use any name for it.
>

Your arguments looks valid, I think we should change how filter works in
release 0.5. This will reduce some possibilities that filter has now with
multiple for-loops, but will make filter method more intuitive and easy to
use.




On Fri, Oct 25, 2013 at 12:59 AM, Vsevolod Novikov <nnseva at gmail.com> wrote:

> Hi Alexander,
>
> > Is this inconvinience particularly one which you meant, or something
>> other?
>>
>> Don't remember I said something like that, I spoke purely about
>> performance of INTERSECT / UNION in SQL
>>
>
> I meant this "This way of filtering should works in the development
> version of Pony (it was accidentally broken in the last release 0.4.8, but
> will be restored in the upcoming release 0.4.9)", but I see now that the
> development version works fine as described.
>
> It will be non-intuitive if parameter name can be arbitrary when query has
>> only one for-loop, but becomes non-arbitrary with multiple for-loops.
>
>
> I didnt mean that.
>
> Look here for example:
>
> >>> d = {
> ...   'a':[1,2,3],
> ...   'b':[4,5],
> ...   'c':[6,7]
> ... }
> >>> [(v,k) for k in d for v in d[k]]
> [(1, 'a'), (2, 'a'), (3, 'a'), (6, 'c'), (7, 'c'), (4, 'b'), (5, 'b')]
>
>
> You can see that the generator turns the first circle and then the second
> one, but always returns only one item - the (v,k) pair - every turn. After
> the evaluating of the generator the only this item remains available for
> the following operations. So, filtering for example, the returned sequence
> we may use only the item value in a filter expression:
>
> >>> filter(lambda x:x[0]==2,[(v,k) for k in d for v in d[k]])
> [(2, 'a')]
>
>
> The same rule should be appied IMHO to the lambda-filter expression which
> is used to filter the query: the only item returned in the query result may
> be used. This particular item is an only lambda parameter of the
> lambda-filter, so we are free to use any name for it.
>
> Another syntax case should be applied IMHO if the filter is included
> DIRECTLY into the generator like here:
>
> >>> [(v,k) for k in d for v in d[k] if v != 1 and k != 'c']
> [(2, 'a'), (3, 'a'), (4, 'b'), (5, 'b')]
>
> The filter here may use any variable in the context of the generator and
> this is usual python language syntax and semantic.
>
> Regards,
> Vsevolod
>
>
> _______________________________________________
> ponyorm-list mailing list
> ponyorm-list at ponyorm.org
> /ponyorm-list
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </ponyorm-list/attachments/20131025/bd99ddcf/attachment-0001.html>


More information about the ponyorm-list mailing list