octave-maintainers
[Top][All Lists]
Advanced

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

Re: Classdef test required on Matlab


From: Laurent Hoeltgen
Subject: Re: Classdef test required on Matlab
Date: Mon, 20 Jan 2014 10:07:57 +0100
User-agent: Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20130509 Thunderbird/17.0.6

On 01/20/2014 06:18 AM, Michael Goffioul wrote:
On Mon, Jan 20, 2014 at 12:17 AM, Michael Goffioul <address@hidden> wrote:
On Sun, Jan 19, 2014 at 10:14 PM, fgnievinski <address@hidden> wrote:
Michael Goffioul wrote
> On Sun, Jan 19, 2014 at 12:36 PM, Lukas Reichlin <

> lukas.reichlin.lists@

>> wrote:
>
>> On 19.01.2014, at 17:42, Michael Goffioul &lt;

> michael.goffioul@

> &gt;
>> wrote:
>>
>> > Could someone test the following in Matlab? Put all files into a single
>> dir, then run "runAll".
>> >
>> > Thanks,
>> > Michael.
>> >
>> >
> <clA.m>
> <clB.m>
> <clC.m>
> <runAll.m>
>>
>> Here you go :-) R2013a on a Mac.
>>
>> Cheers,
>> Lukas
>>
>> >> runAll
>> >>> calling aa.getPropFromA
>> >>> clA::subsref
>>
>> ans =
>>
>>     10
>>
>> >>> calling bb.getPropFromA
>> >>> clA::subsref
>>
>> ans =
>>
>>     10
>>
>> >>> calling bb.getPropFromB
>> >>> clA::subsref
>>
>> ans =
>>
>>     10
>>
>> >>> calling cc.getPropFromC
>> >>> clA::subsref
>>
>> ans =
>>
>>     10
>>
>> >>
>
>
> Thanks. However, this is rather unexpected. I was reading documentation
> about overloading subsref [1] and the documentation says that built-in
> subsref is always called from withing class methods. So unless I'm
> mis-reading the doc, the first case should at least not have called
> clA::subsref. This doesn't make sense...
>
> Michael.
>
>
> [1]
> http://www.mathworks.com/help/matlab/matlab_oop/indexed-reference-and-assignment.html#br09nsm

clA::subsref is being reached directly from runAll, not through method
getPropFromA.

modifying subsref as follows:

    function y = subsref (this, S)
      disp('>>> clA::subsref');
      display(dbstack(1))
      display(S)
      y = this.prop;
    end

shows that:

    >>> calling aa.getPropFromA
    >>> clA::subsref
        file: 'runAll.m'
        name: 'runAll'
        line: 5


    S =

        type: '.'
        subs: 'getPropFromA'


    ans =

        10


on the other hand, calling the method explicitly,
does NOT reach the overload subsref, as expected:

    >> getPropFromA(aa)

    ans =

        10


Of course. By overloading subsref, I inadvertently killed the dot-notation, so I was actually not calling getPropFromA. Thanks for pointing this out.

Would you mind running the test with this modified runAll.m?

And here's the file.

Michael.


Hi,
result on Matlab R2012a and R2013a (it's identical in both versions):

>> aa = clA;
bb = clB;
cc = clC;
disp('>>> calling aa.getPropFromA');
getPropFromA(aa)
disp('>>> calling bb.getPropFromA');
getPropFromA(bb)
disp('>>> calling bb.getPropFromB');
getPropFromB(bb)
disp('>>> calling cc.getPropFromC');
getPropFromC(cc)
>>> calling aa.getPropFromA

ans =

    10

>>> calling bb.getPropFromA

ans =

    10

>>> calling bb.getPropFromB

ans =

    10

>>> calling cc.getPropFromC
>>> clA::subsref

ans =

    10

Regards,
Laurent

reply via email to

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