octave-maintainers
[Top][All Lists]
Advanced

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

Question about tree_index_expression::lvalue()


From: Michael Goffioul
Subject: Question about tree_index_expression::lvalue()
Date: Fri, 24 May 2013 22:49:33 -0400

Hi John,

I'm trying to understand part of the code in tree_index_expression::lvalue() and I was hoping you could give me a hint.

My problem starts with the following classdef test class (ClassA.m):

classdef ClassA
        properties
                prop;
        end
        methods
                function obj = ClassA()
                        disp('ClassA constructor');
                end
                function obj = set.prop (obj, value)
                        disp ('ClassA.set.prop');
                        obj.prop = value;
                end
                function value = get.prop (obj)
                        disp ('ClassA.get.prop');
                        value = obj.prop;
                end
        end
end

Using the current classdef branch, if you type the following at octave prompt:

x = ClassA()
x.prop.a = 10

you'll see the following debug lines (I'm only printing the relevant lines):

ClassA.get.prop                                                                                                                                          
ClassA.get.prop                                                                                                                                          
ClassA.set.prop                                                                                                                                          

In other words, the get access method is called twice. This is unexpected; according to Matlab documentation [1], it should only be called once.

When tracing the code, I found out that the first call to the get access method is due to the fact that tree_index_expression::lvalue calls subsref (around line 462). But I can't figure out why or what's the use case. I know that part of the code has been heavily modified by Jaroslav, but maybe you have some insight.

When looking at the history of changes for that part of the code, it looks like the "subsref" call would only occur in case of magic end or magic colon. But that restriction eventually disappeared.

Michael.

[1] http://www.mathworks.com/help/matlab/matlab_oop/property-access-methods.html#brh8ht7


reply via email to

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