On Mon, Nov 16, 2015 at 6:11 PM, Robert Collins <robe...@robertcollins.net> wrote: > On 17 November 2015 at 14:49, Donald Stufft <don...@stufft.io> wrote: > ... >>> ('name', [], [], (('posix', '==', 'dud'), [('and', ('posix', '==', >>> 'odd')), ('or', ('posix', '==', 'fred'))])) >>> >>> which can just be rolled up left to right. >> >> Should we use the same rules as Python in order to maintain compatibility or >> is there a compelling reason to break compatibility here? > > So for clarity: > True and -> right hand side evaluated stand alone > False and -> False > True or -> True > False or -> right hand side evaluated stand alone > > We can roll that up using the parse tree: > (('posix', '==', 'dud'), [('and', ('posix', '==', 'odd')), ('or', > ('posix', '==', 'fred'))])) > evaluate the start to get a 'result' > pop an expression from the beginning of the list giving opcode, next. > lookup (result, opcode) in the above truth table, giving one of True, > False, None > on None, result = next and loop. > on True or False, return that.
Not sure if we're communicating or not? The case I'm concerned about is a or b and c which Python parses as (a or (b and c)) because 'and' has higher precedence than 'or'. So for example in Python, True or True and False returns True, but if you use a left-to-right evaluation rule than it returns False. -n -- Nathaniel J. Smith -- http://vorpus.org _______________________________________________ Distutils-SIG maillist - Distutils-SIG@python.org https://mail.python.org/mailman/listinfo/distutils-sig