Reaching subtrees

François Pinard pinard at iro.umontreal.ca
Fri Sep 17 18:22:55 EDT 1999


Wow!  Re-wow!  Look:

>>> for (a, (b, c)) in [(1, ((2, 3), (4, 5))), ((11, 12), (13, 14))]: 
...	print a, b, c
... 
1 (2, 3) (4, 5)
(11, 12) 13 14
>>> def x(a, (b, c)):
...	print a, b, c
... 
>>> x(1, ((2, 3), (4, 5)))
1 (2, 3) (4, 5)
>>> x((11, 12), (13, 14))
(11, 12) 13 14

So, if I understand and believe what I see, it might be quite easy in
Python to reach precise subtrees of trees, given that skeletons match?
This, combined with `try:' statements, I guess one could fastly see is some
tree matches a fixed skeleton, and then rebuild it differently if it does.
Is this fully documented, and meant to be a dependable part of the language?

This feature pushes Python forward for elegant writing for simple, modest,
fixed transformational grammars, which is something I happen to often need.
This is worth more investigation.  Moreover, who knows, for non fixed
grammars, maybe there is still some way to reach the underlying mechanics in
the application?  (Short of using `exec', of course!)  For bigger grammars,
optimisation and preconditioning is usually necessary, but maybe Python
could be a nice vehicle for such needed preparation, itself, given the
underlying mechanics is later accessible on the result of the preparation.

Am I making sense to anybody?  Would someone know any Python work in that
direction which I could admire, then shamelessly use for inspiration? :-)

-- 
François Pinard   http://www.iro.umontreal.ca/~pinard





More information about the Python-list mailing list