octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: f(end) feature?


From: John W. Eaton
Subject: Re: f(end) feature?
Date: Tue, 31 Dec 2002 15:47:02 -0600

On 31-Dec-2002, Paul Kienzle <address@hidden> wrote:

| So I guess the following is out of the question:
| 
|       function y = head(x)
|           y = x(1:min(3,end));
|       end

Sorry, that's not what I intended, and it's not actually prevented by
the previous patch, but min(3,end) would return -1, so you would not
get the result you expect.  The following patch should help (I think).

With it and the previous patch:

  octave:1> function y = head (x) y = x(1:min(3,end)); end
  octave:2> x = [1,2,3,4]
  x =

    1  2  3  4

  octave:3> head (x)
  ans =

    1  2  3

and

  octave:1> min (1,end)
  error: __end__: internal error
  error: evaluating argument list element number 2


Is that better?

The error message could be improved, I suppose.

jwe


2002-12-31  John W. Eaton  <address@hidden>

        * pt-arg-list.cc (F__end__): Fail if rows or columns is negative.
        (tree_argument_list::convert_to_const_vector): Only protect and
        save pointer to the indexed object if it is a constant.


Index: pt-arg-list.cc
===================================================================
RCS file: /usr/local/cvsroot/octave/src/pt-arg-list.cc,v
retrieving revision 1.13
diff -u -r1.13 pt-arg-list.cc
--- pt-arg-list.cc      31 Dec 2002 20:16:38 -0000      1.13
+++ pt-arg-list.cc      31 Dec 2002 21:43:14 -0000
@@ -137,11 +151,19 @@
 octave_value_list
 tree_argument_list::convert_to_const_vector (const octave_value *object)
 {
-  unwind_protect::begin_frame ("convert_to_const_vector");
+  // END doesn't make sense for functions.  Maybe we need a different
+  // way of asking an octave_value object this question?
+
+  bool stash_object = (object && object->is_constant ());
 
-  unwind_protect_ptr (indexed_object);
+  if (stash_object)
+    {
+      unwind_protect::begin_frame ("convert_to_const_vector");
+
+      unwind_protect_ptr (indexed_object);
 
-  indexed_object = object;
+      indexed_object = object;
+    }
 
   int len = length ();
 
@@ -214,7 +236,8 @@
 
   args.resize (j);
 
-  unwind_protect::run_frame ("convert_to_const_vector");
+  if (stash_object)
+    unwind_protect::run_frame ("convert_to_const_vector");
 
   return args;
 }



reply via email to

[Prev in Thread] Current Thread [Next in Thread]