|
| From: | anonymous |
| Subject: | [Octave-bug-tracker] [bug #55523] default argument of anonymous function is not bound to value of local variable |
| Date: | Fri, 15 May 2020 23:51:33 -0400 (EDT) |
| User-agent: | Mozilla/5.0 (Windows NT 5.1; rv:60.9) Goanna/4.1 PaleMoon/28.2.0a1 |
Follow-up Comment #9, bug #55523 (project octave):
The bug submitter is here.
I think I was wrong in reporting this behavior as bug and I apologize in
advance!
The function definition:
function foo (a = b)
disp (a)
end
When called as foo () is translated to:
function foo ()
a = b;
disp (a)
end
It means that the default value expression is evaluated in the context of the
function that I think it is compatible with the MATLAB's new argument
validation syntax:
https://www.mathworks.com/help/matlab/matlab_prog/function-argument-validation-1.html
In the argument validation syntax we can define a default value and it is
evaluated in the context of the function and it can be any "constant" or
"expression".
In the case of nested function:
function bar ()
a = 1;
k = 7;
function foo (a = a)
end
foo ()
end
It is evaluated as:
function bar ()
a = 1;
k = 7;
function foo ()
- "a" and "k" are/can be captured from the nesting scope
- define local variable "a" (it gets undefined value)
and it hides the "a" that is in the nesting scope
- "a = a" now should be no-op operation but because we
assigning undefined value to a variable an error
message is shown.
end
foo ()
end
However for some unknown reasons the MATLAB's argument validation syntax is
disallowed in nested functions (should the default value in nested functions
be prohibited?).
So I think this bug can be closed as it seems that the current behavior of
Octave is OK.
_______________________________________________________
Reply to this item at:
<https://savannah.gnu.org/bugs/?55523>
_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/
| [Prev in Thread] | Current Thread | [Next in Thread] |