Possible issue with disp and inputname

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Possible issue with disp and inputname

José Abílio Matos
Hi,
  I have class where I would like to display the name of the variable in the
disp method.

Something like (MWE):

classdef dispbug
    methods
        function obj=dispbug()
        end
        function disp(obj)
            disp(inputname(1))
        end
    end
end

Calling it I get:
>> format compact
>> xx = dispbug();
>> xx
xx =


>> disp(xx)
xx

As far as I understand what is going on this happens because when I call just
xx it calls display(xx) that call disp probably as an expression. I am
guessing and I could have looked into the code. :-)

Apparently this code works in matlab. I say apparently because I asked a
colleague to test the full version and it works, I says something like:

>> xx
xx =
xx

If there is no assigned name then inputname returns ans.

This seems to be a a minor incompatibility with matlab.
While searching for similar bugs in savannah I found
https://savannah.gnu.org/bugs/?49794

although related this does not seem to be the same issue.

Should I report this to savannah?

Best regards,
--
José Matos



Reply | Threaded
Open this post in threaded view
|

Re: Possible issue with disp and inputname

nrjank
Apparently this code works in matlab. I say apparently because I asked a
colleague to test the full version and it works, I says something like:

>> xx
xx =
xx

confirming using Octave 5.2.0 and Matlab 2020a:

Octave: 

octave:4> format compact   
octave:5> xx = dispbug()
xx =


octave:6> xx
xx =


octave:7> disp(xx)
xx

Matlab:

>> format compact
>> xx = dispbug()
xx =
xx
>> disp(xx)
xx