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

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

[Octave-bug-tracker] [bug #55523] default argument of anonymous function


From: John W. Eaton
Subject: [Octave-bug-tracker] [bug #55523] default argument of anonymous function is not bound to value of local variable
Date: Thu, 14 May 2020 17:21:34 -0400 (EDT)
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Firefox/68.0

Follow-up Comment #6, bug #55523 (project octave):

I think the problem with default argument values is a problem with the way
functions are called and is not specific to anonymous functions.  For example,
I see the same problem with an ordinary function:


octave> function foo (a = b) disp (a), end
octave> b = 1
b = 1
octave> foo ()
error: 'b' undefined near line 1, column 1
error: called from
    foo


If we use a constant or a function call to initialize the argument, then it
works:


octave> function foo (a = 13) disp (a), end
octave> foo () 
13

octave> function foo (a = ones(2)) disp (a), end
octave> foo ()
   1   1
   1   1


Maybe I'm wrong about this, but I don't expect the function to capture the
default argument values at the time it is parsed.  Instead, I expect the
initialization expression to be evaluated at the point of the function call. 
Where should the initialization values come from?  I don't think they should
be values in the scope of the function itself.

So should we look to find them in the scope where the function call happens? 
That makes the evaluation a bit complicated, looking for values in the calling
stack frame and storing them in the function stack frame.

Maybe it would be better to limit the initialization values to be either
constants or functions?


    _______________________________________________________

Reply to this item at:

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

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/




reply via email to

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