Today is my 74th birthday. This Engineering Notebook post is my birthday 
present to myself.


For the last week, I have been trying to make paste-retaining-clones work. 
Unit tests show this command improperly computes v.parents arrays in the 
pasted outline.


This morning I saw the way forward:


*Aha!* paste-retaining-clones must recompute *all* v.parents arrays in the 
entire outline!


I won't attempt a formal proof, but I am sure this Aha is correct. Note 
that the paste-node command does *not *require the complications described 
next.


*Recomputing v.parents*


But how to recompute v.parents?


- We can't use Position generators because they all use v.parents!
- We can't use VNode generators because they don't yield VNodes in outline 
order.


*Aha! *Define a *c.all_vnode_positions* generator. This *hybrid generator* will 
yield VNodes in the same order as p.all_positions *using neither v.parents 
nor Positions.* 


Is it possible to write this generator? Yes, it is. The generator will 
maintain an explicit stack just like Position.stack. *Note*: 
c.all_vnode_positions must yield the hidden root VNode.


*Recomputing all v.parents*


Supposing the new generator exists, recomputing all v.parents arrays is 
straightforward. Something like this (untested):


for v in c.all_vnode_positions():

    v.parents = []

for v in c.all_vnode_positions():

    for child in v.children:

        child.parents.append(v)


Yes, a one-pass solution is possible. It *might* be faster.


*Summary*


*Aha!* The paste-retaining-clones command must recompute *all *v.parents 
ivars. This recomputation is sound. The link correction in 
c.checkVnodeLinks is not.


Leo can use neither Position nor VNode generators to do the recomputation.


*Aha!* A new generator, *c.all_vnode_positions*, will yield all VNodes in 
outline order using neither v.parents nor Positions.


Given this generator, updating all v.parents ivars will be straightforward.


Edward


P.S. Let us define a *hybrid generator *as a generator yielding VNodes in 
the same order as some Position generator *without *using Positions.


Could Leo replace Position generators with hybrids? I think not. For 
example, please take a look qtree.full_redraw. It would not be fun to 
eliminate Positions there.


In any event, Leo's Position class is never going away :-)


EKR

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to leo-editor+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/leo-editor/ac395ee0-7d14-47fa-989f-d78139168c50n%40googlegroups.com.

Reply via email to