octave-bug-tracker
[Top][All Lists]
Advanced

[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: Sat, 19 Sep 2020 18:34:58 -0400 (EDT)
User-agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:80.0) Gecko/20100101 Firefox/80.0

Follow-up Comment #47, bug #58953 (project octave):

Great! Thank you Guillaume.

I think I have it. I attach a patch to be applied on top of the patch sent by
jwe from comment #40.

Guillaume, can you confirm that it works for your example? I tried it with
myclass4 and myclass5 and it works.

I also tested it with this class:


lassdef myclass6 < handle
  properties
    data_
  end
  methods
    function obj = myclass6(data)
      obj.data_ = data;
    end
    function r = subsref(obj,S)
      fprintf('-----------------\n')
      S.type
      S.subs
      fprintf('-----------------\n')
      if strcmp(S(1).type,'.') && strcmp(S(1).subs,'data')
        % Transform: obj.data --> obj.data_
        S(1).subs='data_';
      elseif strcmp(S(1).type,'()')
        % Transform: obj(index) --> obj.data_(index)
        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);
      % We subtract 1 from the "real" end of obj.data_
      r = builtin('end',obj.data_,k,n)-1;
    end
  end
end


The tests were:


octave:6> obj.data(end)
-----------------
ans = .
ans = data
-----------------
-----------------
ans = .
ans = ()
ans = data
ans =
{
  [1,1] = 5
}
-----------------
ans = 5
octave:7> obj(end)
'end' called with index=1 of 1
-----------------
ans = ()
ans =
{
  [1,1] = 4
}
-----------------
ans = 4


The results are the same in Matlab.

    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?58953>

_______________________________________________
  Mensaje enviado vía Savannah
  https://savannah.gnu.org/




reply via email to

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