Re: ENB: Ahas re paste-retaining-clones

2023-08-13 Thread vitalije
Actually v_gen2 can be written differently to retain the same API as 
v_generator:

def v_gen2(v):
for ch in v.children:
yield ch
yield from v_gen2(ch)



On Monday, August 14, 2023 at 7:48:11 AM UTC+2 vitalije wrote:

> Happy birthday to you Edward. But putting birthday aside, I can't resist 
> to comment on some parts of your post.
>
>
> On Sunday, August 13, 2023 at 11:31:16 AM UTC+2 Edward K. Ream wrote:
>
> Today is my 74th birthday. This Engineering Notebook post is my birthday 
> present to myself.
>
> - We can't use VNode generators because they don't yield VNodes in outline 
> order.
>
>
>
> I really don't know where did you get this idea from? Have you test it? 
> For me they always give me the nodes in the outline order. Maybe we don't 
> use the same generator? Here is mine:
>
> def v_generator(v):
> yield v
> for ch in v.children:
> yield from v_generator(ch)
>
> a = ('hidden-root-vnode-gnx',) + tuple(p.gnx for p in c.all_positions())
> b = tuple(v.gnx for v in v_generator(c.hiddenRootNode))
>
> assert a == b
>
> # of coarse you can avoid yielding root vnode with
> # a slightly different generator
>
> def v_gen2(vs):
> for ch in vs:
> yield ch
> yield from v_gen2(ch.children)
>
> # and it can be used like this
>
> a = tuple(p.gnx for p in c.all_positions())
> b = tuple(v.gnx for v in v_gen2(c.hiddenRootNode.children))
> assert a == b
> g.es('ok')
>
> The parents attribute is never used in this generators so it is completely 
> free to be modified by the scripts. The information about outline order is 
> fully contained in the v.children attributes. The v.parents attribute is 
> necessary only if you want to continue traversal in outline order from any 
> given point.
>
> Vitalije
>

-- 
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/c31ce713-2ee4-432d-8ef1-09184f156e78n%40googlegroups.com.


Re: ENB: Ahas re paste-retaining-clones

2023-08-13 Thread vitalije
Happy birthday to you Edward. But putting birthday aside, I can't resist to 
comment on some parts of your post.


On Sunday, August 13, 2023 at 11:31:16 AM UTC+2 Edward K. Ream wrote:

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

- We can't use VNode generators because they don't yield VNodes in outline 
order.



I really don't know where did you get this idea from? Have you test it? For 
me they always give me the nodes in the outline order. Maybe we don't use 
the same generator? Here is mine:

def v_generator(v):
yield v
for ch in v.children:
yield from v_generator(ch)

a = ('hidden-root-vnode-gnx',) + tuple(p.gnx for p in c.all_positions())
b = tuple(v.gnx for v in v_generator(c.hiddenRootNode))

assert a == b

# of coarse you can avoid yielding root vnode with
# a slightly different generator

def v_gen2(vs):
for ch in vs:
yield ch
yield from v_gen2(ch.children)

# and it can be used like this

a = tuple(p.gnx for p in c.all_positions())
b = tuple(v.gnx for v in v_gen2(c.hiddenRootNode.children))
assert a == b
g.es('ok')

The parents attribute is never used in this generators so it is completely 
free to be modified by the scripts. The information about outline order is 
fully contained in the v.children attributes. The v.parents attribute is 
necessary only if you want to continue traversal in outline order from any 
given point.

Vitalije

-- 
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/3ddc42e6-6c0f-48b2-90d5-e838ff4743c9n%40googlegroups.com.


Re: ENB: Ahas re paste-retaining-clones

2023-08-13 Thread Edward K. Ream
On Sunday, August 13, 2023 at 2:17:56 PM UTC-5 Viktor wrote:

Another one joining late - but - still in time ;-)


There's no rush, hehe. 

Enjoy your birthday exactly the way you prefer to !


I'm having way too much fun. Time to rejoin my family :-)

Edward

-- 
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/f1f14bd9-5e00-4b73-a6a6-a70ad80a201fn%40googlegroups.com.


Re: ENB: Ahas re paste-retaining-clones

2023-08-13 Thread Edward K. Ream
On Sun, Aug 13, 2023 at 12:10 PM Edward K. Ream wrote:

> c.*alt*_all_positions must use a stack just like Position.stack.

True, but c.alt_all_positions is simpler than I dared hope:

def alt_all_positions(self) -> Generator:
"""An alternative implementation of c.all_positions."""
c = self
PositionStack = list[tuple[VNode, int]]

def visit(childIndex: int, v: VNode, stack: PositionStack) -> Generator:
yield leoNodes.Position(v, childIndex, stack[:])
stack.append((v, childIndex))
for child_childIndex, child_v, in enumerate(v.children):
yield from visit(child_childIndex, child_v, stack)
stack.pop()

stack: PositionStack = []
for i, v in enumerate(c.hiddenRootNode.children):
yield from visit(i, v, stack)

No helper methods required! This method passes
TestNodes.test_c_alt_all_positions:

def test_c_alt_all_positions(self):

c = self.c
self.clean_tree()
cc = self.create_test_paste_outline()
assert cc.h == 'cc', repr(cc)
positions1 = list(c.all_positions())
positions2 = list(c.alt_all_positions())
assert positions1 == positions2

An amazing development. The birthday presents keep coming.

Edward

-- 
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/CAMF8tS0hu1U6Hs8Fqe64PkEKkay9EdDC7qQWHZws0GreeSv4PQ%40mail.gmail.com.


Re: ENB: Ahas re paste-retaining-clones

2023-08-13 Thread Viktor Ransmayr
Hello Edward,

On Sun, 13 Aug 2023, 21:06 Félix,  wrote:

> Edward, I also want to join my voice to the group in wishing you a happy
> birthday! :D


Another one joining late - but - still in time ;-)

Enjoy your birthday exactly the way you prefer to !

>

-- 
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/CAAeSrGKV2JgbCSV1a-2%2BoOyC6V38U15evDsXiMmRtYGUBA0P7A%40mail.gmail.com.


Re: ENB: Ahas re paste-retaining-clones

2023-08-13 Thread Edward K. Ream
On Sunday, August 13, 2023 at 2:06:19 PM UTC-5 Félix wrote:

Edward, I also want to join my voice to the group in wishing you a happy 
birthday! :D

So Happy Birthday, Edward! 

Another year older, but your programming prowess keeps getting younger!
Cheers to you and the adventures your code will take us on! 


Many thanks, my friend.

Edward

-- 
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/3a636ead-07e5-4176-b274-e5cda7182253n%40googlegroups.com.


Re: ENB: Ahas re paste-retaining-clones

2023-08-13 Thread Félix
Edward, I also want to join my voice to the group in wishing you a happy 
birthday! :D

So Happy Birthday, Edward! 

Another year older, but your programming prowess keeps getting younger!
Cheers to you and the adventures your code will take us on! 

Félix

On Sunday, August 13, 2023 at 2:31:58 PM UTC-4 Edward K. Ream wrote:

> On Sun, Aug 13, 2023 at 1:10 PM Thomas Passin  wrote:
>
>> Best wishes on your birthday  from this quarter, too!
>>
>
> :-)
>
> Edward
>

-- 
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/9a2985f3-e8d3-433b-b206-149431374fc8n%40googlegroups.com.


Re: ENB: Ahas re paste-retaining-clones

2023-08-13 Thread Edward K. Ream
On Sun, Aug 13, 2023 at 1:10 PM Thomas Passin  wrote:

> Best wishes on your birthday  from this quarter, too!
>

:-)

Edward

-- 
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/CAMF8tS3EM%2Bxx%3DW_COtVCcj6wr3ec9E1vcXvEkPeit%3DiBSu0heA%40mail.gmail.com.


Re: ENB: Ahas re paste-retaining-clones

2023-08-13 Thread Thomas Passin
Best wishes on your birthday  from this quarter, too!

On Sunday, August 13, 2023 at 1:13:18 PM UTC-4 Edward K. Ream wrote:

On Sunday, August 13, 2023 at 12:00:43 PM UTC-5 David Szent-Györgyi wrote:

> Thank you for working on your birthday and giving a gift to us all. 


-- 
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/febb50e1-9da7-44fe-b726-d418dcbc174en%40googlegroups.com.


Re: ENB: Ahas re paste-retaining-clones

2023-08-13 Thread Edward K. Ream
On Sunday, August 13, 2023 at 12:00:43 PM UTC-5 David Szent-Györgyi wrote:

> Thank you for working on your birthday and giving a gift to us all. 

You're welcome. It's been my pleasure.

Edward

-- 
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/537ae5c6-5828-4e2f-b579-49d73b48421an%40googlegroups.com.


Re: ENB: Ahas re paste-retaining-clones

2023-08-13 Thread Edward K. Ream
On Sun, Aug 13, 2023, Edward K. Ream wrote:


>> Is it possible to write [*c.all_vnode_positions*]?

> You bet: [snip]

> This generator passes the following consistency test:


vnodes1 = [c.hiddenRootNode] + [z.v for z in c.all_positions()]

vnodes2 = list(c.all_vnode_positions())

assert vnodes1 == vnodes2


The elegance of this VNode-based stand-in for c.all_positions raises some
follow-on questions.


*Does c.all_positions use v.parents?*


Apparently not, which means that c.all_vnode_positions isn't strictly
necessary. Leo could define it like this:


def all_vnode_positions(self):

c = self

yield c.hiddenRootNode

for p in c.all_positions():

yield p.v


But this definition would be much worse than a VNode-based definition.


*c.alt_all_positions*


Could Leo define a generator, say *c.alt_all_positions*, using
c.all_vnode_positions as a template? Yes it could.


In my original post, I said, "[c.all_vnode_positions] will maintain an
explicit stack just like Position.stack." In fact, the generator uses only
a stack of VNodes. But c.*alt*_all_positions must indeed use a stack just
like Position.stack.


c.all_positions calls p.moveToThreadNext to advance through the outline. In
turn, p.moveToThreadNext calls p.moveToParent, p.moveToFirstChild and
p.moveToNext.


c.*alt*_all_positions will use none of these helpers. Instead, the new
generator will operate directly on its explicit stack, yielding new
positions with (copies of) the explicit stack. There will be no need for a
"copy" kwarg.


*Summary*


*c.alt_all_positions* is feasible. Similarly, Leo could define other "alt"
generators.


Alt generators should be faster (and use less memory) than the
corresponding legacy generators.


Nevertheless, Positions themselves and all Position methods must remain,
whatever their internal form.


Edward

-- 
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/CAMF8tS1-NtBYKghZHe1rPZaRcFa6x5GKavzsLyioF%2BgnhA_19A%40mail.gmail.com.


Re: ENB: Ahas re paste-retaining-clones

2023-08-13 Thread David Szent-Györgyi
On Sunday, August 13, 2023 at 5:31:16 AM UTC-4 Edward K. Ream wrote:

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


Have the happiest of  birthdays. Thank you for working on your birthday and 
giving a gift to us all. 

-- 
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/510e2cf7-cf7c-482e-acfb-42af7196b0b4n%40googlegroups.com.


Re: ENB: Ahas re paste-retaining-clones

2023-08-13 Thread Edward K. Ream
On Sun, Aug 13 Edward K. Ream wrote:

> Is it possible to write [*c.all_vnode_positions*]?


You bet:


def all_vnode_positions(self) -> Generator:
c = self
to_be_visited: list[VNode] = [c.hiddenRootNode]
while to_be_visited:
v = to_be_visited.pop()
yield v
for child in reversed(v.children):
to_be_visited.append(child)


This generator passes the following consistency test:


vnodes1 = [c.hiddenRootNode] + [z.v for z in c.all_positions()]
vnodes2 = list(c.all_vnode_positions())

assert vnodes1 == vnodes2


Edward

-- 
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/CAMF8tS1rwk6A6QnYeCoVwKEcJ6RiAxhUS8DRzLa4VbdOztUbTQ%40mail.gmail.com.


Re: ENB: Ahas re paste-retaining-clones

2023-08-13 Thread Edward K. Ream
On Sun, Aug 13, 2023 at 4:50 AM jkn  wrote:

> Well, Happy Birthday Edward! ;-)
>

Thanks :-)

Edward

-- 
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/CAMF8tS0grWE7S%3DX8d80Bw8o62EriiJBUAKoRayYXJZWh2j6xgg%40mail.gmail.com.


Re: ENB: Ahas re paste-retaining-clones

2023-08-13 Thread jkn
Well, Happy Birthday Edward! ;-)

Regards, Jon N


On Sunday, August 13, 2023 at 10:31:16 AM UTC+1 Edward K. Ream wrote:

> 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/667252b3-0580-4a72-ab5e-29154440d1d8n%40googlegroups.com.


ENB: Ahas re paste-retaining-clones

2023-08-13 Thread Edward K. Ream
 

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.