From octave-maintainers-request at bevo dot che dot wisc dot edu Tue Dec 31 14:16:30 2002 Subject: f(end) feature? From: "John W. Eaton" To: Paul Kienzle Cc: octave-maintainers at bevo dot che dot wisc dot edu Date: Tue, 31 Dec 2002 14:16:14 -0600 On 31-Dec-2002, Paul Kienzle wrote: | octave:1> function y=f(x), y=x; end | octave:2> f(end) | ans = 1 Try the following patch. With it, you should see octave:1> function y = f (x) y = x; end octave:2> f (end) error: invalid use of end error: evaluating argument list element number 1 jwe 2002-12-31 John W. Eaton * pt-arg-list.cc (F__end__): Fail if rows or columns is negative. Index: pt-arg-list.cc =================================================================== RCS file: /usr/local/cvsroot/octave/src/pt-arg-list.cc,v retrieving revision 1.12 diff -u -r1.12 pt-arg-list.cc --- pt-arg-list.cc 21 Dec 2002 17:15:25 -0000 1.12 +++ pt-arg-list.cc 31 Dec 2002 20:15:07 -0000 at @ -104,7 +104,15 @@ { case -1: // XXX FIXME XXX -- we really want "numel" here. - retval = indexed_object->rows () * indexed_object->columns (); + { + int nr = indexed_object->rows (); + int nc = indexed_object->columns (); + + if (nr < 0 || nc < 0) + ::error ("invalid use of end"); + else + retval = nr * nc; + } break; case 0: