[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Expected behavior for variables which shadow function names
From: |
Julien Bect |
Subject: |
Re: Expected behavior for variables which shadow function names |
Date: |
Fri, 08 Mar 2013 10:13:34 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20130221 Thunderbird/17.0.3 |
On 07/03/2013 20:13, John W. Eaton wrote:
Some things to test:
function f (jet)
jet
end
Here is what I think the answer should be (based on my own Matlab user
experience) :
f() --> not enough input arguments
f(0) --> 0
f(1) --> 1
The fact that the symbol "jet" refers to a variable is determined IMO
when Matlab first parses the function. Therefore, even if nargin == 0,
jet is assumed to refer to a variable in the context of this function.
function f (jet)
if (nargin == 0)
jet
elseif (nargin == 1)
x = jet
end
end
Same thing IMO, for the same reasons.
function f ()
jet = 1;
clear jet
jet
end
I think this should generate an error : when the function is parsed,
Matlab determines that "jet" refers to a local variable in this function.
Therefore, the third line of code should generate an error since jet has
been cleared.
Best regards,
Julien.