bugGNU Octave - Bugs: bug #44035, unable to subclass built-in types

 
 

bug #44035: unable to subclass built-in types

Submitter:  CarnĂ« Draug <carandraug>
Submitted:  Sun 18 Jan 2015 03:22:55 PM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Feature Request
Status:  Confirmed Assigned to:  None
Originator Name:  Open/Closed:  * Open
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Tue 26 Nov 2019 01:16:47 AM UTC, comment #8: 

comment #7:

> In addition to all those, Matlab's "methods ('double')" returns any methods defined in pwd (or elsewhere in the path) in "@double/foo.m" files.


There seem to be no such methods/subdir for 'double', but there is for 'cell'. For 'cell' class, methods() does report the functions in toolbox/matlab/ops/@cell subdir.

As a side note, not treating builtin types as first-class objects, impedes adoption of classdef considerably.


Stas M <smax1>
Fri 19 Apr 2019 08:06:59 AM UTC, comment #7: 

In addition to all those, Matlab's "methods ('double')" returns any methods defined in pwd (or elsewhere in the path) in "@double/foo.m" files.

Colin Macdonald <cbm>
Fri 19 Apr 2019 05:19:45 AM UTC, comment #6: 


>> methods ('double')

Methods for class double:

abs
acos
acosd
acosh
acot
acotd
acoth
acsc
acscd
acsch
airy
amd
and
append
asec
asecd
asech
asin
asind
asinh
atan
atan2
atan2d
atand
atanh
...



too much to paste here.

Mike Miller <mtmiller>
Group Member
Thu 18 Apr 2019 08:31:40 PM UTC, comment #5: 

In Matlab, what does


methods ('double')


report?

John W. Eaton <jwe>
Group administrator
Thu 18 Apr 2019 07:17:13 AM UTC, comment #4: 

Thanks, Mike, it makes sense. Just be careful writing that all of them can be subclassed -- if i remember correctly, you cannot (yet?) subclass struct, cell, char and function_handle, they are "sealed".

sergey plotnikov <nul0m>
Thu 18 Apr 2019 06:14:42 AM UTC, comment #3: 

No, numeric types or structs are not classdef classes in Matlab, even though they do share a lot of properties with classdef classes. I would say yes to comment #1, they behave like classdef objects in some cases, but they are not actually classdef objects.

The 'isobject' function returns false for numeric types, logical, char, cell, struct, and function handles for example, so they are not classes in that sense. But they can have overridden methods, they can be used with the 'methods', 'properties', and 'metaclass' functions, and can be subclassed.

Mike Miller <mtmiller>
Group Member
Thu 18 Apr 2019 05:33:10 AM UTC, comment #2: 

What would be the core difference between "being considered" and "behave like"? According to https://www.mathworks.com/help/matlab/matlab_oop/subclassing-matlab-built-in-classes.html I would say built-in are pretty similar to classdef -- you can check their metadata, subclass them and overload their methods.

sergey plotnikov <nul0m>
Wed 17 Apr 2019 06:26:36 PM UTC, comment #1: 

Changing title since this is a general problem with all built-in types.

In Matlab, are built-in types like "double" or "struct" considered to be classdef objects, or do they just behave like classdef objects in some cases (subclassing, overloading methods, etc.)?

John W. Eaton <jwe>
Group administrator
Sun 18 Jan 2015 03:22:55 PM UTC, original submission:  

I was trying to subclass double but found it does not work in octave.  The following snippet, taken straight from Matlab documentation, fails with "error: class not found: double"


classdef DocSimpleDouble < double
   methods
      function obj = DocSimpleDouble(data)
         if nargin == 0
            data = 0;
         end
         obj = obj@double(data); % initialize the base class portion
      end
   end
end


Carnë Draug <carandraug>
Group Member

 

(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 smax1 (Posted a comment)
  • -email is unavailable- added by cbm (Posted a comment)
  • -email is unavailable- added by nul0m (Posted a comment)
  • -email is unavailable- added by jwe (Posted a comment)
  • -email is unavailable- added by cbm
  • -email is unavailable- added by rik5 (Updated the item)
  • -email is unavailable- added by nul0m
  • -email is unavailable- added by carandraug (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 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2019-04-17 jwe Summaryclassdef is unable to to subclass double unable to subclass built-in types
    2018-01-20 cbm Carbon-Copy- Added cbm
    2015-04-24 rik5 StatusNone Confirmed
    2015-03-06 nul0m Carbon-Copy- Added -email is unavailable-

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code