Define how set assigns through missing paths and constructs new data #15
Labels
No labels
bug
duplicate
enhancement/documentation
enhancement/feature
enhancement/organization
question
rejected
upstream
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
UserCurt/mpath#15
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
If creating a struct from scratch, an existing idiomatic approach is to assign a field on each line in MATLAB:
Implementation of this proposal would allow for creation of structs from scratch using mpath expression syntax. This could be implemented as a variant of
mpath.set:Dimension specifiers could be set for additional clarity or to match the size of the value being assigned.
Perhaps MultiSet could be assumed to be true when using this variant of
mpath.set.This syntax would treat structs specially over tables or classes. It is unclear if this could translate to classes. To translate this over to tables, separate named argument or function would be needed. Alternatively, new functions could be considered completely rather than using
mpath.set:This would translate into NamedArray (not yet publicly released) nicely as
mpath.NamedArray(...)or similar (see #23).Dimension for tables could specify the level within the table.
set#10This issue is being broadened past struct creation without existing data. It should define how
set(and the chunk planner) handles concrete missing path suffixes and how to handle circumstances where MPath needs to explicitly know the newly formed datatype.Current behavior
Currently,
setincrementally addresses eachDotExact. When an intermediate member is missing from a struct, MPath creates another struct.It can also replace an existing non-struct intermediate value with a struct:
This implicit struct creation should change as it prevents MATLAB or a custom class from receiving the original chained assignment (
indexOparray) and deciding what that assignment means.Native assignment first
When the path suffix after the last successfully retrieved value consists of fully specified indexing operations, MPath should preserve that suffix as one assignment operation (chunk) and delegate it to MATLAB. For example:
should not require MPath to create
A,B, andCseparately. MATLAB handles this naturally for structs, while a custom class may define different behavior.If part of the path has already been materialized, the remaining concrete suffix can still be assigned together:
In MPath terms, traversal might produce a route such as:
The first chunk
/A<1>would be the normal materialized traversal and write-back route. However, the second chunk/B/C/Dis a concrete assignment-only suffix for non-existing elements, beginning after the last materialized parent.Missing paths and chunking
Once traversal reaches a missing member, the read-oriented chunk planner cannot test the rest of the path because there is no value to retrieve or inspect. The same path suffix may still be valid when used for assignment. So the mutation planning should distinguish:
The assignment-only suffix should normally remain intact rather than being split into inferred intermediate structs.
Explicit chunk boundaries may still require MPath to materialize an intermediate value. Forward and reverse chunk planning for those cases is related to #45. Shared write-back routes across multiple actions are tracked by #47.
No implicit type inference
MPath should not infer intermediate container types from path syntax.
MissingPolicy="create"should mean that MPath preserves an eligible concrete missing suffix and attempts native assignment through it. It should not mean that every missing intermediate is assumed to be a struct.MPath may still require an intermediate value when:
When MPath must continue traversal through a missing intermediate value, it should not guess what type of container to create. It should report an error unless the caller explicitly specifies the required type or how to construct it.
A future API could provide this information through a factory, prototype, or schema. Specialized functions could make the choice directly:
mpath.structwould create structs, whilempath.tablewould create tables. In each case, the API or caller selects the type rather than MPath inferring it from the path.Policy behavior
The design should define how native creation interacts with:
MissingPolicy="create"and"prune"NonmissingRequirementUniformPathsandUniformValuesCreate struct from scratch usingto Define howsetsetassigns through missing paths and constructs new dataRoot values should also be considered in this issue and not handled specially or differently. For example, assigning
/Aon a non-container root and assigning/X/Awhendata.Xis a non-container should behave the same.Completed by
ab1236b. Member creations are now mainly done throughdata.(indexOps) = ....Creating something from nothing is deemed out of scope for
setso is not part of this commit.