matnwb icon indicating copy to clipboard operation
matnwb copied to clipboard

Support Map-like `subsref` and `subsasgn` overload for `types.untyped.Set` types.

Open lawrence-mbf opened this issue 3 years ago • 7 comments

Calling get/set all the time isn't quite idiomatic MATLAB.

lawrence-mbf avatar Feb 18 '22 16:02 lawrence-mbf

this would be cool!

bendichter avatar Feb 18 '22 17:02 bendichter

though let's think about how we would support any names that have spaces in them

bendichter avatar Feb 18 '22 17:02 bendichter

Since Sets are already backed by containers.Map there isn't an issue in storing. We would just have to imitate its method for mapping string keys to values:

value = nwb.processing('some data');
nwb.processing('some data') = SomeType;

lawrence-mbf avatar Feb 18 '22 17:02 lawrence-mbf

We'd just have to be careful never to accidentally shadow any methods in Set itself (size, fcn, etc.)

lawrence-mbf avatar Feb 18 '22 17:02 lawrence-mbf

how about nwb.processing.some_data?

bendichter avatar Feb 18 '22 17:02 bendichter

That would require changing the internals of the Set to use Dynamic Properties instead. I don't think you can do this with subsref and subsasgn. It would also require a separate cache which saves the property's true name as well as checking for strange collisions like a Set with the properties (some data, some-data, and some_data).

lawrence-mbf avatar Feb 18 '22 17:02 lawrence-mbf

ok, sounds like your solution is simpler and less risky

bendichter avatar Feb 18 '22 20:02 bendichter