Add exists to suite of traversal functions and methods to check if path exists #8

Closed
opened 2025-10-11 03:54:59 +00:00 by UserCurt · 2 comments
UserCurt commented 2025-10-11 03:54:59 +00:00 (Migrated from codeberg.org)

It can be useful to check whether a given field exists in a struct. The proposed method/function is analogous to MATLAB's isfield and exist functions. There would be a mpath.exist function and an mpath.Pointer.exist method. The function/method will return a logical depending on whether the field exists or not.

S = struct(A=struct(X=1, Y=2), B=struct(X=3));
mpath.exist(S, "/B/X") % true
mpath.exist(S, "/B/Y") % false
mpath.exist(S, "/*/*") % [true true; true false]

Alternatively, if mpath.ConcretePointer is to be implemented as described in #6, it could contain a property for whether the path exists or not. Then one could have a few options:

mpath.exist(S, "/*/*")
mpath.exist(S, mpath.resolve("/*/*", NullField="retain", FillGaps=true))
mpath.resolve(S, "/*/*", NullField="retain", FillGaps=true).exist()
It can be useful to check whether a given field exists in a struct. The proposed method/function is analogous to MATLAB's `isfield` and `exist` functions. There would be a `mpath.exist` function and an `mpath.Pointer.exist` method. The function/method will return a logical depending on whether the field exists or not. ```matlab S = struct(A=struct(X=1, Y=2), B=struct(X=3)); mpath.exist(S, "/B/X") % true mpath.exist(S, "/B/Y") % false mpath.exist(S, "/*/*") % [true true; true false] ``` Alternatively, if `mpath.ConcretePointer` is to be implemented as described in #6, it could contain a property for whether the path exists or not. Then one could have a few options: ```matlab mpath.exist(S, "/*/*") mpath.exist(S, mpath.resolve("/*/*", NullField="retain", FillGaps=true)) mpath.resolve(S, "/*/*", NullField="retain", FillGaps=true).exist() ```
UserCurt commented 2026-07-19 15:31:59 +00:00 (Migrated from codeberg.org)

Since this issue was created, some things have changed.

Name changes:

  • mpath.exists(data, path, ...)
  • path.exists(data, ...)

Other changes:

  • NullField was replaced by MissingPolicy and NonmissingRequirement
  • FillGaps was replaced by MissingPolicy="missing" and SizeMismatchPolicy="fill"
  • ConcretePointer was not introduced. Concrete, missing, and unreached state is now tracked as internal traversal metadata
Since this issue was created, some things have changed. Name changes: - `mpath.exists(data, path, ...)` - `path.exists(data, ...)` Other changes: - `NullField` was replaced by `MissingPolicy` and `NonmissingRequirement` - `FillGaps` was replaced by `MissingPolicy="missing"` and `SizeMismatchPolicy="fill"` - `ConcretePointer` was not introduced. Concrete, missing, and unreached state is now tracked as internal traversal metadata
UserCurt commented 2026-07-19 23:21:29 +00:00 (Migrated from codeberg.org)

Implemented in e91fdb8.

Implemented in `e91fdb8`.
Sign in to join this conversation.
No description provided.