|
From: Robin M. <rob...@gm...> - 2006-06-08 13:04:35
|
On 6/8/06, Michael Foord <fuz...@vo...> wrote: > Robin Munn wrote: > > Here's the patch. This one implements a *proper* recursive, > > lazy-loading interpolation approach, and no longer suffers from the > > "stop when a $$ is seen" problem. If anything stops interpolation of > > one key, the rest of the keys in the string will not have their > > interpolation stopped. Thus, "$foo + $bar + $baz" will follow "$baz" > > all the way down the interpolation tree even if "$foo" immediately > > evaluates to "$$99.95" (which becomes "$99.95" and stops interpolation > > of "$foo"). > > > > Thanks for this Robin. > > I'm going to have to take some time to understand this and work out what > is really going on. :-) > > It sounds good though, appreciated. > > Fuzzyman > http://www.voidspace.org.uk/python/index.shtml Think of the interpolation values as nodes of a directed, acyclic graph (a tree, basically), and the dependencies between them as the edges of the graph (or the branches on the tree). E.g., if you have "bar = $foo" then the node "bar" is the parent of the node "foo". The patch I submitted basically does a depth-first search on that graph (or a basic root-to-leaves traversal of the tree, if you prefer to think of it that way) until it reaches the endnodes of the graph (the leaves of the tree), which have no interpolated values in them. Then, using those "final" (no more interpolation needed) values, it climbs back up the tree until it reaches the root again, and returns with the final value. I wish I had a whiteboard; I could explain this so much better with diagrams. :-) -- Robin Munn Rob...@gm... GPG key 0xD6497014 |