Dot operation by numerical index #2
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#2
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?
Structs and tables have ordered fields and variables. This feature request is to add support for indexing these by numerical index.
In its most basic form, it would be a single positive integer following the path separator:
/1. Duringresolve, if out of range, it would throw an error depending on the value ofNullField. For multiple indices, there are various points that will have to be considered below. The syntax on these is not final.Equally spaced indices: Using MATLAB's colon syntax, this would look like
/1:3,/1:2:10.Concatenation: Using MATLAB's colon syntax, this would look like
/[1, 3, 10],/[1, 3:4, 9]. Commas would be optional in this case as long as there is whitespace, like in/[1 3 10],/[1 3:4 9]. Alternatively, dot operation with set notation described in #3 can be re-used here without the need for using new syntax, like in/{1, 3, 10},/{1, 3:4, 9}. Although this deviates from MATLAB's bracket syntax, it matches other syntax in mpath while also avoiding confusion with brackets proposed in a yet-created issue on filtering.Last element: Using the same
endkeyword as MATLAB,/{1 end}. Note that/endwill not access the last field but rather the field namedend. Similarly, if using set notation,/{1, end}would treatendas a field name. Some notation like parenthesis would have to be introduced to make this unambiguous, like in/(end)or/{1, (end)}. Whenendis used in this manner, it does not look so elegant. A value of 0 or -1 would work if used by itself but would not handle operations described below. A symbol could be used in place of the keywordend:/$,/^,/@, `` -- none of these I am fond of. It could be surrounded or prefixed with$,like in/$end,/{1, $end}or/$end$,/{1, $end$}, which would work well with the$syntax in the not-yet-created feature request proposing referencing variables from within an mpath expression.Grouping and operations: In colon syntax, it can be helpful to reference the last element, like in
/1:2:end. Also, math is often applied to the last element, which can often require grouping, like in:/(end-1),/(end/2),/((end-1)/2). This can work fine for general arithmetic, but it is unclear if or how to apply operations like floor, ceiling, and round. This could require a general framework of calling functions from within an mpath string. These could be prefixed with$like before.This syntax will have much similarity with syntax to be used in paren and brace operations. Usage of
[]notation may be preferred over{}for this fact alone as braces wouldn't normally be used within parenthesis or braces in MATLAB indexing. Though the mpath syntax does not have to mirror MATLAB identically, so usage of{}syntax should still be a consideration.One consideration not discussed so far is the representation of these in a string conversion of an mpath pointer after parsing an mpath expression since representations are not unique. The comment here discusses it in the context of parenthesis operations #5, and they similarly translate to this issue.
An early version of
DotIndexwas introduced in commit5c538e6. It was removed in commit86502e0during cleanup in preparation for v1 release but can be re-introduced in the future when this issue is being addressed.endand expressions in numeric indices #52