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

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

[Octave-bug-tracker] [bug #37179] isequal(@XXX, @XXX) is not compatible


From: Rik
Subject: [Octave-bug-tracker] [bug #37179] isequal(@XXX, @XXX) is not compatible
Date: Mon, 27 Aug 2012 19:19:31 +0000
User-agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:14.0) Gecko/20100101 Firefox/14.0.1

Follow-up Comment #4, bug #37179 (project octave):

I don't necessarily want to duplicate Matlab's behavior if it is a lot of
work.  But, they do seem to have chosen a reasonable strategy.  For example,
the Octave parser also defers symbol table lookups when we are processing
subfunctions in the same .m file.  I'm thinking of the following:


In file manyfuncs.m

function y = manyfuncs (x)
  tmp = @func1;
  y = tmp (x);
endfunction

function y = func1 (x)
  tmp = @func2;
  y = tmp (x);
endfunction

function y = func2 (x)
  y = @sin (x);
endfunction


The parser encounters @func1 before it has been defined so it has to treat it
as a generic reference until the rest of the file has been parsed.  I don't
see why, on the command line, Octave should require the object behind the
function handle to exist if we are not actually using the object.  When you do
need the object, such as to evaluate the function handle with some input and
produce an output, then it is required for the object to exist, but not before
that point.

More possible example code, typed at the command line.


clear all
function y = func1 (x)
  y = @func2 (x);
endfunction
## This completes okay even though func2 does not exist
func1 (1)
error: @func2: no function and no method found
error: evaluating argument list element number 1
error: called from:
error:   func1 at line 2, column 5
## This errors out as expected because the object is undefined
## Now define func2
function y = func2 (x)
  y = sin (x);
endfunction
func1 (1)
ans =  0.84147
## Now it completes as expected.


It seems like it would be nice to me to allow this kind of code where the
handle to the object is used early before the definition of the object behind
it.


clear all
myfcn = @func2;  # Currently this errors out, but imagine it continuing
function y = func2 (x)
  y = sin (x);
endfunction
myfcn (1)  # Only here, when I ask for an evaluation of the object behind the
           # reference should I check and get an error if func2 is undefined.




    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?37179>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

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