Skip to content

Commit

Permalink
doc: Add notes to 'end' docstring about class and subsref limation (b…
Browse files Browse the repository at this point in the history
…ug #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.
  • Loading branch information
NRJank committed Feb 2, 2024
1 parent 7d588a5 commit 05d3256
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions libinterp/parse-tree/pt-eval.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2280,6 +2280,31 @@ last valid entry in an indexing operation.
@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 */)
{
Expand Down

0 comments on commit 05d3256

Please sign in to comment.