Phillip J. Eby wrote: > I tried doing something like this when I was writing RuleDispatch, and gave > up in disgust because there's no sane way to implement "and" and "or" > operations with this approach. The bitwise operators (&, |, and ~) bind > too tightly to be used with comparison expressions, so doing something like > "x>y & z" would mean "x>(y&z)" instead of "(x>y)&z".
How would symbols, or ast access have helped you with that problem? Would you really go around manually mangling the parse tree to move the "&" higher in the branches somehow? > So if you could backquote code to make an AST literal, you could spell > RuleDispatch overrides like: > @pprint_when(`isinstance(ob,list) and len(ob)<10`) > def pprint_short_list(ob): > ... > And the database query use case could be done using something like: > db.query(`(row for row in some_table if row.x>42)`)" > > Perhaps the backquote isn't the right character for this; What do you think about the oft-maligned curly brace? @pprint_when({isinstance(ob,list) and len(ob)<10}) def pprint_short_list(ob): db.query( {(row for row in some_table if row.x>42)} ) ? Not too heinous, in my view. And it should be possible to tell the difference between it and a dict with a bit of a lookahead... (Really it's the conflict with dict initialization that I expect to kill this proposal.) Later, Blake. _______________________________________________ Python-3000 mailing list Python-3000@python.org http://mail.python.org/mailman/listinfo/python-3000 Unsubscribe: http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com