ENB: About immutable positions

47 views
Skip to first unread message

Edward K. Ream

unread,
Jul 15, 2023, 10:12:09 AM7/15/23
to leo-editor

This ENB will try to make sense of Vitalije's idea of immutable positions. Let's call them Imps :-) Leo's Position and VNode objects must stay as they are. However, as a thought experiment, we can imagine adding Imps to leo.


Don't get your hopes up. Imps are not a good idea.


What would an immutable position be?


If I understand Vitalije, an Imp would continue to exist when the outline changes. Leo could implement imps as a pair of dictionaries. One dict would associate Positions with Imps; the other would associate Imps with Positions. Immutable positions would have global position indices (gpxs) similar to gnxs.


Leo's position class would have to keep these two dicts up to date when moving, inserting, cloning, or deleting nodes. It won't be easy, but this is a thought experiment.


What problems would Imps solve?


None, imo:


- Imps may become invalid if the underlying VNode disappears.

- Difficult code like c.deletePositionsInList doesn't get any easier.

g.app.p_to_ap and g.app.ap_to_p suffice to restore c.p on startup.

- gnx-based clickable links moot the need for Imps.


Summary


Leo could (as a thought experiment) implement Imps as a pair of dictionaries.


Imps would exist in addition to Positions and VNodes. The Position class would have to keep the dictionaries up to date. That task would not be fun. Mistakes would be catastrophic.


Imps solve no urgent problem, nor do they solve existing problems more simply.


gnx-based clickable links moot the need for Imps. Let's find new ways to use Leo's new clickable links!


Edward

Edward K. Ream

unread,
Jul 15, 2023, 5:49:29 PM7/15/23
to leo-editor

My initial post in this thread showed how Leo could support Imps (Immutable Positions) without changing Leo's Position or VNode classes. I concluded that Imps were not a good idea :-)


Vitalije not-so-subtly implies that Positions are a blunder. This post refutes that notion.


Positions are the foundation of Leo's generators.


The great Bernhard Mulder proposed using generators such as c.all_positions and p.self_and_subtree. Much of Leo's scripting prowess is the direct result of generators.


Positions have a natural meaning.


Positions correspond to outline order in a fully-expanded outline. This easily-understood meaning carries over to the corresponding generators.


The algorithms of the Position class are solid.


Generators work because Leo's position class makes them work. The algorithms underlying generators are non-trivial, as you can discover for yourself. Leo's representation of positions makes the algorithms as straightforward as possible.


Summary


Positions give Leo much of its scripting power. Their meaning, representation, and algorithms are easily understood and as simple as possible.


It is insulting to imply that positions are defective.


Those who think they have a better way can create a Leo plugin or even a fork of Leo. They can then discover for themselves whether replacing positions would work. They do not need my permission for their experiments, and they need not convince me beforehand that their ideas have merit.


Waiting a year won't change my opinion. Only a complete demonstration of fully functional code could do that.


Edward

Thomas Passin

unread,
Jul 15, 2023, 6:40:07 PM7/15/23
to leo-editor
On Saturday, July 15, 2023 at 5:49:29 PM UTC-4 Edward K. Ream wrote:

My initial post in this thread showed how Leo could support Imps (Immutable Positions) without changing Leo's Position or VNode classes. I concluded that Imps were not a good idea :-)


Vitalije not-so-subtly implies that Positions are a blunder. This post refutes that notion.


Positions are the foundation of Leo's generators.


The great Bernhard Mulder proposed using generators such as c.all_positions and p.self_and_subtree. Much of Leo's scripting prowess is the direct result of generators.


It seems to me that one has to - or nearly has to - have something like positions.  Why? Because otherwise a node would need to know where it is in the tree, but nodes can be (and must be) duplicated or multiply referenced so that Leo can have clones.  Either the tree itself must know that or the outline must contain something that does.  That something can't be the VNodes themselves because clones.

If we think of a Leo tree as a container, then it can't be a container of VNodes.  So a tree must be a container of something else:  Hello, Positions!

This line of thought doesn't mandate any particular form for Positions or even that they be classes.  That's a design and implementation matter.

As for generators, I'm not wedded to them as generators;  they could be methods that return lists, and I suppose they were once upon a time.  Probably having them as generators has a benefit I haven't discovered as yet (aside from possibly saving some memory, which may not be that much of an issue these days).  If we wanted to pass one of them around with its iteration partly executed, that would make a difference but I haven't seen a need to do that.

Edward K. Ream

unread,
Jul 15, 2023, 6:44:48 PM7/15/23
to leo-e...@googlegroups.com
On Sat, Jul 15, 2023 at 5:40 PM Thomas Passin <tbp1...@gmail.com> wrote:

> It seems to me that one has to...have something like positions.

I agree, of course.

> generators...could be methods that return lists.

Doing without generators would be an unpythonic mistake.

Edward
Reply all
Reply to author
Forward
0 new messages