How can function argument declaration be introspected?
10 views (last 30 days)
Show older comments
Is there a way to programmatically access the function argument validation declared in the argument block? meta.method introspection only allows to determine argument names, but I am interested in all of the validation features (dimensions, class, validation functions).
My need especially focuses on functions (not only class methods) and also on output arguments.
3 Comments
Sean
on 8 Aug 2024
This is an old question with no answers. So I assume there was no way to do this back in 2022. Has there been any changes? I am also very interested in doing this.
Umar
on 8 Aug 2024
Edited: Walter Roberson
on 8 Aug 2024
Hi @Simon Sigl,
As I am aware of argument validation enhances code readability and maintainability by enforcing specific input and output requirements. However, traditional introspection methods, such as `meta.method`, only reveal argument names without detailing the associated validation criteria (e.g., size, class). I doubt that if there is no built-in method for programmatically accessing full argument validation details declared in the `arguments` block. Also, the`meta.method` class provides some metadata but does not extend to validation features. I would suggest implementing a mechanism within your functions to document validations explicitly using structured data.Use documentation comments to describe validations, enhancing code readability. Explore `meta.class` along with `meta.method` for structured understanding of class methods. Please bear in mind that Output arguments can also be validated, but similar strategies apply for introspection.
Here are some useful links that will help your aid in your research.
In nutshell, while direct programmatic access to detailed argument validations in MATLAB is currently limited, utilizing custom structures and thorough documentation can effectively address these challenges. Future updates may further improve these capabilities.
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!