bugGNU Octave - Bugs: bug #29456, class() should work for any method

 
 

bug #29456: class() should work for any method

Submitter:  Judd Storrs <judd>
Submitted:  Tue 06 Apr 2010 07:40:27 PM UTC
   
 
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Wont Fix Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * dev Operating System:  * GNU/Linux
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Wed 07 Apr 2010 05:39:12 PM UTC, comment #4: 

I have never seen the "bless" feature that you described.  Where is it documented?  If that is something that Octave should also have, then please open another bug report (as a feature request) and give a pointer to some documentation for the feature.

John W. Eaton <jwe>
Group administrator
Wed 07 Apr 2010 05:19:06 PM UTC, comment #3: 

The code that I stumbled over this in appears to be going about subsref-ing a structure array in a strange way that sort of looks like it should be easier to do. Probably this code represents a kludge around limitations of an older Matlab release. Matlab's current error codes indicate that class() can only be used in a constructor.

Please close this bug report with "won't fix".

Judd Storrs <judd>
Wed 07 Apr 2010 03:31:35 AM UTC, comment #2: 

Sorry, that was meant for bug 29447.

Judd Storrs <judd>
Wed 07 Apr 2010 03:29:36 AM UTC, comment #1: 

Here's another patch that improves on the earliest one. Instead of returning a string it returns an invalid handle. I think the behavior is much better:


octave:1> func = @crash
warning: @crash: no function and no method found
func = @crash
octave:2> func()
error: crash: no longer valid function handle
octave:2> feval(func)
error: crash: not a valid function handle
octave:2>



diff -r 6cf7d7665d57 src/ov-fcn-handle.cc
--- a/src/ov-fcn-handle.cc        Fri Apr 02 13:08:11 2010 -0400
+++ b/src/ov-fcn-handle.cc        Tue Apr 06 23:24:21 2010 -0400
@@ -1523,7 +1523,11 @@
             }
         }
       else
-        error ("@%s: no function and no method found", tnm.c_str ());
+        {
+          warning ("@%s: no function and no method found", tnm.c_str ());
+          octave_fcn_handle *fh = new octave_fcn_handle (f, tnm);
+          retval = fh;
+        }
     }

   return retval;
diff -r 6cf7d7665d57 src/ov-fcn-handle.h
--- a/src/ov-fcn-handle.h        Fri Apr 02 13:08:11 2010 -0400
+++ b/src/ov-fcn-handle.h        Tue Apr 06 23:24:21 2010 -0400
@@ -96,7 +96,14 @@
   dim_vector dims (void) const { static dim_vector dv (1, 1); return dv; }

   octave_function *function_value (bool = false)
-    { return fcn.function_value (); }
+    {
+      octave_function *retval = 0;
+      if (fcn.is_defined ())
+        retval = fcn.function_value ();
+      else
+        error ("%s: not a valid function handle", nm.c_str ());
+      return retval ;
+    }

   octave_user_function *user_function_value (bool = false)
     { return fcn.user_function_value (); }


Judd Storrs <judd>
Tue 06 Apr 2010 07:40:27 PM UTC, original submission:  

Octave prevents use of class() outside the constructor, however Matlab appears to allow class() inside any method.

Consider:


@foo/foo.m:
function obj = foo()
  obj.data = 'Hello' ;
  obj = class(obj,'foo') ;

@foo/disp.m:
function disp(f)
   disp(struct(f))

@foo/bless.m:
function obj = bless(f,s)
  obj = class(s,'foo') ;


Matlab allows bless to convert any structure with the correct fields into a foo-object.


>> a = foo()
a =
        foo object: 1-by-1
>> disp(a)
    data: 'Hello'
>> b.data = 'World'
b =
    data: 'World'
>> b = bless(a,b)
b =
        foo object: 1-by-1
>> disp(b)
    data: 'World'


Octave refuses to allow class() outside of @foo/foo:


octave:1> a = foo()
a = <class foo>
octave:2> disp(a)
{
  data = Hello
}
octave:3> b.data = 'World'
b =
{
  data = World
}
octave:4> b = bless(a,b)
error: class: invalid call from outside class constructor
error: called from:
error:   /tmp/test3/@foo/bless.m at line 2, column 7


Judd Storrs <judd>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by jwe (Posted a comment)
  • -email is unavailable- added by judd (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2010-04-07 jwe StatusNone Wont Fix
        Open/ClosedOpen Closed

    Back to the top

    Powered by Savane 3.13-d3ae.
    Corresponding source code