[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Octave-bug-tracker] [bug #49794] display vs. disp functions
From: |
Amro |
Subject: |
[Octave-bug-tracker] [bug #49794] display vs. disp functions |
Date: |
Fri, 9 Dec 2016 22:20:38 +0000 (UTC) |
User-agent: |
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:45.9) Gecko/20100101 Goanna/3.0 Firefox/45.9 PaleMoon/27.0.2 |
Follow-up Comment #13, bug #49794 (project octave):
I did some more testing, and it seems that Octave calls the correct overloaded
functions. So dispatching works correctly as far as I can tell.
I've used the following classes to cover all four cases of overloading or not
disp/display:
classdef MyClass
properties
x = 0;
end
end
classdef MyClass_Disp
properties
x = 0;
end
methods
function disp(obj)
fprintf('MyClass::disp\n');
end
end
end
classdef MyClass_Display
properties
x = 0;
end
methods
function display(obj)
fprintf('MyClass::display\n');
end
end
end
classdef MyClass_Disp_Display
properties
x = 0;
end
methods
function disp(obj)
fprintf('MyClass::disp\n');
end
function display(obj)
fprintf('MyClass::display\n');
end
end
end
Here is the output in Octave 4.2.0:
% ---------------------------------------------------------------------------
>> x1 = MyClass
x1 =
<object MyClass>
>> disp(x1)
<object MyClass>
>> display(x1)
<object MyClass>
>> builtin('disp', x1)
<object MyClass>
>> builtin('display', x1)
<object MyClass>
% ---------------------------------------------------------------------------
>> x2 = MyClass_Disp
x2 =
MyClass::disp
>> disp(x2)
MyClass::disp
>> display(x2)
MyClass::disp
error: called from
display at line 53 column 7
error: value on right hand side of assignment is undefined
>> builtin('disp', x2)
<object MyClass_Disp>
>> builtin('display', x2)
MyClass::disp
error: called from
display at line 53 column 7
error: value on right hand side of assignment is undefined
% ---------------------------------------------------------------------------
>> x3 = MyClass_Display
MyClass::display
>> disp(x3)
<object MyClass_Display>
>> display(x3)
MyClass::display
>> builtin('disp', x3)
<object MyClass_Display>
>> builtin('display', x3)
<object MyClass_Display>
% ---------------------------------------------------------------------------
>> x4 = MyClass_Disp_Display
MyClass::display
>> disp(x4)
MyClass::disp
>> display(x4)
MyClass::display
>> builtin('disp', x4)
<object MyClass_Disp_Display>
>> builtin('display', x4)
MyClass::disp
error: called from
display at line 53 column 7
error: value on right hand side of assignment is undefined
% ---------------------------------------------------------------------------
Here is the output in MATLAB R2016b:
% ---------------------------------------------------------------------------
>> x1 = MyClass
x1 =
MyClass with properties:
x: 0
>> disp(x1)
MyClass with properties:
x: 0
>> display(x1)
x1 =
MyClass with properties:
x: 0
>> builtin('disp', x1)
MyClass with properties:
x: 0
>> builtin('display', x1)
Error using builtin
Undefined function 'display' for input arguments of type 'MyClass'.
% ---------------------------------------------------------------------------
>> x2 = MyClass_Disp
x2 =
MyClass::disp
>> disp(x2)
MyClass::disp
>> display(x2)
x2 =
MyClass::disp
>> builtin('disp', x2)
MyClass_Disp with properties:
x: 0
>> builtin('display', x2)
Error using builtin
Undefined function 'display' for input arguments of type 'MyClass_Disp'.
% ---------------------------------------------------------------------------
>> x3 = MyClass_Display
MyClass::display
>> disp(x3)
MyClass_Display with properties:
x: 0
>> display(x3)
MyClass::display
>> builtin('disp', x3)
MyClass_Display with properties:
x: 0
>> builtin('display', x3)
Error using builtin
Undefined function 'display' for input arguments of type 'MyClass_Display'.
% ---------------------------------------------------------------------------
>> x4 = MyClass_Disp_Display
MyClass::display
>> disp(x4)
MyClass::disp
>> display(x4)
MyClass::display
>> builtin('disp', x4)
MyClass_Disp_Display with properties:
x: 0
>> builtin('display', x4)
Error using builtin
Undefined function 'display' for input arguments of type
'MyClass_Disp_Display'.
% ---------------------------------------------------------------------------
To get rid of the errors in Octave, I'd have to define "disp" method as
"function varargout = disp(obj)", and return a string if requested, instead of
always printing.
As for MATLAB, apparently it treats "display" in a special manner.. You can
how it errors when called with "builtin" versus directly. I searched the docs
and there was this paragraph mentioned:
* MATLAB adds default methods named disp and display to all MATLAB classes
that do not implement their own methods with those names. These methods are
not visible, but create the default simple display.
One more note; MATLAB does suggest to never overload "display" but instead to
overload "disp". That's because the default "display" function calls "disp" to
handle the actual display of the values, then simply prepends a header when
appropriate (kinda like the version I suggested in comment #7)
Sorry for the long post!
_______________________________________________________
Reply to this item at:
<http://savannah.gnu.org/bugs/?49794>
_______________________________________________
Message sent via/by Savannah
http://savannah.gnu.org/
- [Octave-bug-tracker] [bug #49794] display vs. disp functions, (continued)
- [Octave-bug-tracker] [bug #49794] display vs. disp functions, Amro, 2016/12/09
- [Octave-bug-tracker] [bug #49794] display vs. disp functions, Amro, 2016/12/09
- [Octave-bug-tracker] [bug #49794] display vs. disp functions, Rik, 2016/12/09
- [Octave-bug-tracker] [bug #49794] display vs. disp functions, Amro, 2016/12/09
- [Octave-bug-tracker] [bug #49794] display vs. disp functions, Amro, 2016/12/09
- [Octave-bug-tracker] [bug #49794] display vs. disp functions, Amro, 2016/12/09
- [Octave-bug-tracker] [bug #49794] display vs. disp functions, Rik, 2016/12/09
- [Octave-bug-tracker] [bug #49794] display vs. disp functions, Amro, 2016/12/09
- [Octave-bug-tracker] [bug #49794] display vs. disp functions, John W. Eaton, 2016/12/17
- [Octave-bug-tracker] [bug #49794] display vs. disp functions, Rik, 2016/12/09
- [Octave-bug-tracker] [bug #49794] display vs. disp functions,
Amro <=
- [Octave-bug-tracker] [bug #49794] display vs. disp functions, John W. Eaton, 2016/12/17
- [Octave-bug-tracker] [bug #49794] display vs. disp functions, John W. Eaton, 2016/12/12
- [Octave-bug-tracker] [bug #49794] display vs. disp functions, John W. Eaton, 2016/12/16
- [Octave-bug-tracker] [bug #49794] display vs. disp functions, Rik, 2016/12/16
- [Octave-bug-tracker] [bug #49794] display vs. disp functions, John W. Eaton, 2016/12/16
- [Octave-bug-tracker] [bug #49794] display vs. disp functions, Rik, 2016/12/16
- [Octave-bug-tracker] [bug #49794] display vs. disp functions, John W. Eaton, 2016/12/17
- [Octave-bug-tracker] [bug #49794] display vs. disp functions, John W. Eaton, 2016/12/17
- [Octave-bug-tracker] [bug #49794] display vs. disp functions, Amro, 2016/12/17
- [Octave-bug-tracker] [bug #49794] display vs. disp functions, Amro, 2016/12/17