esainane / pyp

Automatically exported from code.google.com/p/pyp
0 stars 0 forks source link

unexpected parsing of addition/comparison expression #11

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Using a logic filter,

$ for i in 1 2 3 4 5; do echo "$i $i"; done | pyp "(int(w[0])+int(w[1]))>5"
3 3
4 4
5 5

works as expected: it shows only lines whose columns sum to greater than 5. 
Likewise with "(int(w[0])+int(w[1])>5)". However, removing the outer 
parentheses produces an unexpected result:

$ for i in 1 2 3 4 5; do echo "$i $i"; done | pyp "int(w[0])+int(w[1])>4"
1
2
3
4
55 5

This is equivalent to the output with "int(w[0])+(int(w[1])>4)": I think it is 
treating int(w[1])>4 as a logic filter and concatenating its result with the 
value of int(w[0]). In any case, if this is the intended behavior, it should 
probably be documented because it differs from Python's operator precedence 
rules.

Original issue reported on code.google.com by neatn...@gmail.com on 26 Mar 2012 at 11:19

GoogleCodeExporter commented 8 years ago
impressive filtering! This is one of the few changes that is different from 
normal python and is documented under Math Operations here:

http://code.google.com/p/pyp/wiki/pyp_manual

t

Original comment by tobyro...@gmail.com on 26 Mar 2012 at 11:57

GoogleCodeExporter commented 8 years ago
I guess it would be clearer if mentioned under "Logic Filters" as well, since 
it applies not just to arithmetic but to seemingly any complex numeric 
expression: e.g. the filters "int(w[0]) in {1,2,3}" and "len(w[0]) in {1,2,3}" 
don't work without enclosing parentheses.

Original comment by neatn...@gmail.com on 27 Mar 2012 at 12:59

GoogleCodeExporter commented 8 years ago
that's a good point. I'll put a reference there on the next revision.

Original comment by tobyro...@gmail.com on 27 Mar 2012 at 1:20

GoogleCodeExporter commented 8 years ago
I've updated the wiki with a note about this type of function.

Original comment by tobyro...@gmail.com on 27 Mar 2012 at 2:04

GoogleCodeExporter commented 8 years ago
updated twiki. Please try the new beta if you have a chance:
http://code.google.com/p/pyp/downloads/detail?name=pyp_beta&can=2&q=#makechanges

Original comment by tobyro...@gmail.com on 16 May 2012 at 9:39