changeset 32904:cf43680cd221 stable

doc: Add notes to 'end' docstring about class and subsref limation (bug #59737) * libinterp/parse-tree-pt-eval.cc (end): Add programming note indicating that end cannot be used in subsref, subsasgn, substruct for indexing. Add second note describing how end must be overloaded for use in indexing with classes.
author Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
date Thu, 01 Feb 2024 23:33:19 -0500
parents a575aa730d84
children 81d1512a47cb 92e55fcc0c30
files libinterp/parse-tree/pt-eval.cc
diffstat 1 files changed, 25 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/parse-tree/pt-eval.cc	Thu Feb 01 15:46:53 2024 -0800
+++ b/libinterp/parse-tree/pt-eval.cc	Thu Feb 01 23:33:19 2024 -0500
@@ -2280,6 +2280,31 @@
  @result{} 6
 @end group
 @end example
+
+Programming notes:
+@enumerate
+@item
+The @code{end} keyword cannot be used within @code{subsref},
+@code{subsasgn}, or @code{substruct} for manual indexing operations.
+
+@item
+For custom classes, to enable use of @code{end} in indexing expressions it
+must be overloaded with a function definition such as:
+   @example
+   @group
+   function last_index = end (obj, end_dim, ndim_obj)
+     if (end_dim == ndim_obj)
+       last_index = prod (size (obj)(end_dim:ndim_obj));
+     else
+       last_index = size (obj, end_dim);
+     endif
+   endfunction
+   @end group
+   @end example
+For more information see
+@ref{Object Oriented Programming, , Object Oriented Programming}.
+@end enumerate
+
 @seealso{for, parfor, if, do, while, function, switch, try, unwind_protect}
 @end deftypefn */)
 {