changeset 32906:3904d7116c8c bytecode-interpreter

maint: Merge default to byte-codeinterpreter.
author Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
date Thu, 01 Feb 2024 23:34:35 -0500
parents f4d7e6efb2e9 (current diff) 81d1512a47cb (diff)
children c96d0470a582
files libinterp/parse-tree/pt-eval.cc test/Makefile.am
diffstat 3 files changed, 56 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/parse-tree/pt-eval.cc	Thu Feb 01 13:29:04 2024 -0500
+++ b/libinterp/parse-tree/pt-eval.cc	Thu Feb 01 23:34:35 2024 -0500
@@ -2288,6 +2288,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 */)
 {
--- a/test/Makefile.am	Thu Feb 01 13:29:04 2024 -0500
+++ b/test/Makefile.am	Thu Feb 01 23:34:35 2024 -0500
@@ -17,6 +17,7 @@
 
 TEST_FILES += \
   fntests.m \
+  anonymous-function.tst \
   args.tst \
   bug-31371.tst \
   bug-40117.tst \
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/anonymous-function.tst	Thu Feb 01 23:34:35 2024 -0500
@@ -0,0 +1,30 @@
+########################################################################
+##
+## Copyright (C) 2024 The Octave Project Developers
+##
+## See the file COPYRIGHT.md in the top-level directory of this
+## distribution or <https://octave.org/copyright/>.
+##
+## This file is part of Octave.
+##
+## Octave is free software: you can redistribute it and/or modify it
+## under the terms of the GNU General Public License as published by
+## the Free Software Foundation, either version 3 of the License, or
+## (at your option) any later version.
+##
+## Octave is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with Octave; see the file COPYING.  If not, see
+## <https://www.gnu.org/licenses/>.
+##
+########################################################################
+
+%!test <*64783>
+%! s = struct ('re',{pi,2}, 'im',{3,4});
+%! f = @(x) x.re ;
+%! f(s);
+%! assert (ans, pi);