Combining and dividing mpath pointers #18

Open
opened 2025-10-11 13:53:27 +00:00 by UserCurt · 0 comments
UserCurt commented 2025-10-11 13:53:27 +00:00 (Migrated from codeberg.org)

This feature request is to develop a method to compose or decompose mpaths more easily without using strings. There are a couple approaches:

MPath builder with method chaining: The idea is to create a fluent interface to repeatedly apply method calls to build up an MPath Pointer. The details on the best way to do this has not beet fully determined, but below shows a number of approaches:

% Basic idea
mp = mpath.Pointer("/A/*#2")
mp = mpath.Builder.DotExact("A").DotGlob("*", Dimension=2).ToPointer()
mp = mpath.Builder.Dot("A").Dot("*", Dimension=2).ToPointer()
mp = mpath.Builder.A.("*").SetDimension(2).ToPointer()
% With indices (not yet implemented)
mp = mpath.Pointer("/A(:,1)")
mp = mpath.Builder.Dot("A").Paren(":", 1).ToPointer()
mp = mpath.Builder.A(:,1).ToPointer()
% Filters (not yet implemented)
mp = mpath.Pointer("/*[...]")
mp = mpath.Builder.Dot("*", Filter=...).ToPointer()

This can help with building up an MPath but not decomposing an MPath.

A limitation of the notation like mp = mpath.Builder.A.("*").SetDimension(2).ToPointer() is that there could be naming conflicts.

MPath composition: The idea is to define addition operation on MPaths as a way to combine existing mpaths. To do away with parsing strings and to rather work with operations directly, there should be methods to construct pointers that are single operations.
I wonder if it would be possible to have operations in the mpath.operation namespace to inherit mpath.Pointer so that this new interface could be avoided altogether.

mp = mp1 + mp2
mp = mpath.Pointer("/A") + mpath.Pointer("/*") % defining addition
mp = mpath.Pointer.DotExact("A") + mpath.Pointer.DotGlob("*") % new API needed
mp = mpath.operation.DotExact("A") + mpath.operation.DotGlob("*") % modifying existing API

For decomposition, perhaps operations should be opened up to the public API, including construction using operations. For example:

mp2 = mp.Pointer(mp1.Operations(1:end-1)) % remove last operation
This feature request is to develop a method to compose or decompose mpaths more easily without using strings. There are a couple approaches: **MPath builder with method chaining:** The idea is to create a fluent interface to repeatedly apply method calls to build up an MPath Pointer. The details on the best way to do this has not beet fully determined, but below shows a number of approaches: ```matlab % Basic idea mp = mpath.Pointer("/A/*#2") mp = mpath.Builder.DotExact("A").DotGlob("*", Dimension=2).ToPointer() mp = mpath.Builder.Dot("A").Dot("*", Dimension=2).ToPointer() mp = mpath.Builder.A.("*").SetDimension(2).ToPointer() % With indices (not yet implemented) mp = mpath.Pointer("/A(:,1)") mp = mpath.Builder.Dot("A").Paren(":", 1).ToPointer() mp = mpath.Builder.A(:,1).ToPointer() % Filters (not yet implemented) mp = mpath.Pointer("/*[...]") mp = mpath.Builder.Dot("*", Filter=...).ToPointer() ``` This can help with building up an MPath but not decomposing an MPath. A limitation of the notation like `mp = mpath.Builder.A.("*").SetDimension(2).ToPointer()` is that there could be naming conflicts. **MPath composition:** The idea is to define addition operation on MPaths as a way to combine existing mpaths. To do away with parsing strings and to rather work with operations directly, there should be methods to construct pointers that are single operations. I wonder if it would be possible to have operations in the `mpath.operation` namespace to inherit mpath.Pointer so that this new interface could be avoided altogether. ```matlab mp = mp1 + mp2 mp = mpath.Pointer("/A") + mpath.Pointer("/*") % defining addition mp = mpath.Pointer.DotExact("A") + mpath.Pointer.DotGlob("*") % new API needed mp = mpath.operation.DotExact("A") + mpath.operation.DotGlob("*") % modifying existing API ``` --- For decomposition, perhaps operations should be opened up to the public API, including construction using operations. For example: ```matlab mp2 = mp.Pointer(mp1.Operations(1:end-1)) % remove last operation ```
Sign in to join this conversation.
No description provided.