[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: |
Fri, 18 Sep 2020 04:00:21 -0400 (EDT) |
User-agent: |
Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:80.0) Gecko/20100101 Firefox/80.0 |
Follow-up Comment #38, bug #58953 (project octave):
It seems that you are almost there. However, there is some confusion between
builtin and custom methods for subsref and END.
I defined yet another class, which redefines both subsref and END methods:
classdef myclass2 < handle
properties
data
end
methods
function obj = myclass2(data)
obj.data = data;
end
function r = subsref(obj,S)
fprintf('-----------------\n')
S.type
S.subs
fprintf('-----------------\n')
% You can use () directly on obj to access data property
if strcmp(S(1).type,'()')
S = [struct('type','.','subs','data'), S(1:end)];
end
r = builtin('subsref',obj,S);
end
function r = end(obj,k,n)
fprintf('''end'' called with index=%d of %d\n',k,n);
r = builtin('end',obj.data,k,n)-1;
end
end
end
In Matlab, I got:
>> obj=myclass2(1:5)
obj =
myclass2 with properties:
data: [1 2 3 4 5]
>> a=obj.data(end)
-----------------
ans =
'.'
ans =
'data'
-----------------
-----------------
ans =
'.'
ans =
'()'
ans =
'data'
ans =
1×1 cell array
{[5]}
-----------------
a =
5
>> b=obj(end)
'end' called with index=1 of 1
-----------------
ans =
'()'
ans =
1×1 cell array
{[4]}
-----------------
b =
4
but in Octave I got:
octave:1> obj=myclass2(1:5)
obj =
myclass2 object with properties:
data: [1x5 double]
octave:2> a=obj.data(end)
'end' called with index=1 of 1
-----------------
ans = .
ans = ()
ans = data
ans =
{
[1,1] = 4
}
-----------------
a = 4
octave:3> b=obj(end)
'end' called with index=1 of 1
-----------------
ans = ()
ans =
{
[1,1] = 0
}
-----------------
error: index (0): subscripts must be either integers 1 to (2^63)-1 or
logicals
error: called from
subsref at line 17 column 9
When evaluating the instruction a=obj.data(end), the END method should be
evaluated for obj.data, which is an array and not an object, so the builtin
END should be used.
When evaluating b=obj(end), the redefined END method calls the builtin END
method for obj.data, but it seems that Octave's builtin END just ignores the
arguments of that call.
_______________________________________________________
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, 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
- [Octave-bug-tracker] [bug #58953] Error with 'end' in index expression with nested function calls, John W. Eaton, 2020/09/14
- [Octave-bug-tracker] [bug #58953] Error with 'end' in index expression with nested function calls, John W. Eaton, 2020/09/16
- [Octave-bug-tracker] [bug #58953] Error with 'end' in index expression with nested function calls, Guillaume, 2020/09/16
- [Octave-bug-tracker] [bug #58953] Error with 'end' in index expression with nested function calls, John W. Eaton, 2020/09/16
- [Octave-bug-tracker] [bug #58953] Error with 'end' in index expression with nested function calls, Fernando, 2020/09/16
- [Octave-bug-tracker] [bug #58953] Error with 'end' in index expression with nested function calls, Fernando, 2020/09/17
- [Octave-bug-tracker] [bug #58953] Error with 'end' in index expression with nested function calls, John W. Eaton, 2020/09/17
- [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, Guillaume, 2020/09/18
- [Octave-bug-tracker] [bug #58953] Error with 'end' in index expression with nested function calls, John W. Eaton, 2020/09/18
- [Octave-bug-tracker] [bug #58953] Error with 'end' in index expression with nested function calls, Fernando, 2020/09/18
- [Octave-bug-tracker] [bug #58953] Error with 'end' in index expression with nested function calls, Guillaume, 2020/09/18
- [Octave-bug-tracker] [bug #58953] Error with 'end' in index expression with nested function calls, John W. Eaton, 2020/09/19
- [Octave-bug-tracker] [bug #58953] Error with 'end' in index expression with nested function calls, Fernando, 2020/09/19
- [Octave-bug-tracker] [bug #58953] Error with 'end' in index expression with nested function calls, Guillaume, 2020/09/19
- [Octave-bug-tracker] [bug #58953] Error with 'end' in index expression with nested function calls, Guillaume, 2020/09/19
- [Octave-bug-tracker] [bug #58953] Error with 'end' in index expression with nested function calls, Fernando, 2020/09/19
- [Octave-bug-tracker] [bug #58953] Error with 'end' in index expression with nested function calls, Fernando, 2020/09/19