Create new fields using set #10

Closed
opened 2025-10-11 09:23:01 +00:00 by UserCurt · 2 comments
UserCurt commented 2025-10-11 09:23:01 +00:00 (Migrated from codeberg.org)

Normally, mpath.set will assign the value to existing fields. This feature request is to allow mpath.set and mpath.Pointer.set create new fields in structs, variables in tables, and properties in classes with dynamic properties. Usage of mpath.exist from #8 should return true after mpath.set.

Some care may be considered to avoid accidentally creating new fields unintentionally. Perhaps by default attempting to create new fields should result in an error. Providing a named argument CreateNewFields when true would allow creation of new fields.

There is a subtlety to note with two separate behaviors: Creating a new field on an existing struct, or creating a new struct on an existing struct. It is probably best to lump these together with CreateNewFields rather than having each be optional.

Implementation of this feature as proposed would promote structs to be treated specially over tables as, without additional work, it would not be possible to create new variables (columns) in tables using mpath. Some consideration should be put into alternative ways that would treat these more equally.

Normally, `mpath.set` will assign the value to existing fields. This feature request is to allow `mpath.set` and `mpath.Pointer.set` create new fields in structs, variables in tables, and properties in classes with [dynamic properties](https://www.mathworks.com/help/matlab/matlab_oop/dynamic-properties-adding-properties-to-an-instance.html). Usage of `mpath.exist` from #8 should return true after `mpath.set`. Some care may be considered to avoid accidentally creating new fields unintentionally. Perhaps by default attempting to create new fields should result in an error. Providing a named argument `CreateNewFields` when true would allow creation of new fields. There is a subtlety to note with two separate behaviors: Creating a new field on an existing struct, or creating a new struct on an existing struct. It is probably best to lump these together with `CreateNewFields` rather than having each be optional. Implementation of this feature as proposed would promote structs to be treated specially over tables as, without additional work, it would not be possible to create new variables (columns) in tables using mpath. Some consideration should be put into alternative ways that would treat these more equally.
UserCurt commented 2025-10-11 11:07:23 +00:00 (Migrated from codeberg.org)

This feature is pending the completion of #11.

This feature is pending the completion of #11.
Owner

The ability to create fields has been supported. Commit 206e68a introduced MissingPolicy="create", while cf2cf42 extended this to terminal tables and scalar dynamic properties. Validation was addressed in b541c6f usingNonmissingRequirement.

This works for creating new terminal struct fields, table variables, and dynamicprops properties. It also also allows recursively creating intermediate structs, similar to #15.

Issue #11 was completed and closed, while remaining effectively satisfied once moving to a shared traversal engine #40.

MPath still cannot infer the type of intermediate missing values, whether a struct, table variable, or object property. This broader construction design will be tracked in #15.

The ability to create fields has been supported. Commit `206e68a` introduced `MissingPolicy="create"`, while `cf2cf42` extended this to terminal tables and scalar dynamic properties. Validation was addressed in `b541c6f` using`NonmissingRequirement`. This works for creating new terminal struct fields, table variables, and `dynamicprops` properties. It also also allows recursively creating intermediate structs, similar to #15. Issue #11 was [completed and closed](https://git.usercurt.com/UserCurt/mpath/issues/11#issuecomment-37_), while remaining effectively satisfied once moving to a shared traversal engine #40. MPath still cannot infer the type of intermediate missing values, whether a struct, table variable, or object property. This broader construction design will be tracked in #15.
Sign in to join this conversation.
No description provided.