[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Octave-bug-tracker] [bug #58953] Error with 'end' in index expression w
From: |
Fernando |
Subject: |
[Octave-bug-tracker] [bug #58953] Error with 'end' in index expression with nested function calls |
Date: |
Thu, 10 Sep 2020 19:37:16 -0400 (EDT) |
User-agent: |
Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:80.0) Gecko/20100101 Firefox/80.0 |
Follow-up Comment #20, bug #58953 (project octave):
I have done some tests in Matlab (2020a) to understand how expressions
involving subsref and end are processed. Maybe it can help. However, it seems
complex and I don't know if it is worth the effort to fix this issue.
So if you want to read on, I defined the following class
classdef myclass < handle
properties
data
end
methods
function obj = myclass(data)
obj.data = data;
end
function r = methodA (obj, val)
r = val;
end
function r = subsref(obj,S)
fprintf('-----------------\n')
S.type
S.subs
fprintf('-----------------\n')
r = ones(1,3);
end
end
end
and the following function
function r = f(x)
r=x;
end
Then I executed:
>> obj=myclass(1:5)
obj =
myclass with properties:
data: [1 2 3 4 5]
>> obj.data(end)
-----------------
ans =
'.'
ans =
'data'
-----------------
-----------------
ans =
'.'
ans =
'()'
ans =
'data'
ans =
1×1 cell array
{[3]}
-----------------
ans =
1 1 1
The subsref method is called twice. The first one evaluates obj.data, and its
result is used to call the end method. The second one evaluates the complete
expression: obj.data(3).
Another case:
>> x=1:5
x =
1 2 3 4 5
>> obj.data(x(end))
-----------------
ans =
'.'
ans =
'()'
ans =
'data'
ans =
1×1 cell array
{[5]}
-----------------
ans =
1 1 1
In this case only one invocation to subsref is necessary.
Another case:
>> obj.data(idem(end))
-----------------
ans =
'.'
ans =
'data'
-----------------
-----------------
ans =
'.'
ans =
'()'
ans =
'data'
ans =
1×1 cell array
{[3]}
-----------------
ans =
1 1 1
The expression looks very similar to the previous one, but now "end" refers to
obj.data, so two subrefs are done.
It seems that Matlab tries to evaluate "idem(end)" before "obj.data", but
finds an "end" that is refering to "obj.data" and evaluates "obj.data" on the
fly.
_______________________________________________________
Reply to this item at:
<https://savannah.gnu.org/bugs/?58953>
_______________________________________________
Mensaje enviado vía Savannah
https://savannah.gnu.org/
- [Octave-bug-tracker] [bug #58953] Error with 'end' in index expression with nested function calls, (continued)
- [Octave-bug-tracker] [bug #58953] Error with 'end' in index expression with nested function calls, John W. Eaton, 2020/09/08
- [Octave-bug-tracker] [bug #58953] Error with 'end' in index expression with nested function calls, John W. Eaton, 2020/09/08
- [Octave-bug-tracker] [bug #58953] Error with 'end' in index expression with nested function calls, Guillaume, 2020/09/09
- [Octave-bug-tracker] [bug #58953] Error with 'end' in index expression with nested function calls, Rik, 2020/09/09
- [Octave-bug-tracker] [bug #58953] Error with 'end' in index expression with nested function calls, Fernando, 2020/09/09
- [Octave-bug-tracker] [bug #58953] Error with 'end' in index expression with nested function calls, John W. Eaton, 2020/09/09
- [Octave-bug-tracker] [bug #58953] Error with 'end' in index expression with nested function calls, John W. Eaton, 2020/09/09
- [Octave-bug-tracker] [bug #58953] Error with 'end' in index expression with nested function calls, John W. Eaton, 2020/09/09
- [Octave-bug-tracker] [bug #58953] Error with 'end' in index expression with nested function calls, Guillaume, 2020/09/09
- [Octave-bug-tracker] [bug #58953] Error with 'end' in index expression with nested function calls, John W. Eaton, 2020/09/09
- [Octave-bug-tracker] [bug #58953] Error with 'end' in index expression with nested function calls,
Fernando <=
- [Octave-bug-tracker] [bug #58953] Error with 'end' in index expression with nested function calls, Fernando, 2020/09/10
- [Octave-bug-tracker] [bug #58953] Error with 'end' in index expression with nested function calls, John W. Eaton, 2020/09/10
- [Octave-bug-tracker] [bug #58953] Error with 'end' in index expression with nested function calls, Fernando, 2020/09/11
- [Octave-bug-tracker] [bug #58953] Error with 'end' in index expression with nested function calls, John W. Eaton, 2020/09/11
- [Octave-bug-tracker] [bug #58953] Error with 'end' in index expression with nested function calls, Fernando, 2020/09/11
- [Octave-bug-tracker] [bug #58953] Error with 'end' in index expression with nested function calls, John W. Eaton, 2020/09/11
- [Octave-bug-tracker] [bug #58953] Error with 'end' in index expression with nested function calls, Fernando, 2020/09/11
- [Octave-bug-tracker] [bug #58953] Error with 'end' in index expression with nested function calls, Fernando, 2020/09/11
- [Octave-bug-tracker] [bug #58953] Error with 'end' in index expression with nested function calls, Fernando, 2020/09/12
- [Octave-bug-tracker] [bug #58953] Error with 'end' in index expression with nested function calls, Fernando, 2020/09/12