[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Expected behavior for variables which shadow function names
From: |
Rik |
Subject: |
Expected behavior for variables which shadow function names |
Date: |
Thu, 07 Mar 2013 10:18:41 -0800 |
3/7/13
All,
I ran across an odd behavior and I wanted to know what other people thought
was "correct".
For the following function:
function y = tstflag (flag)
y = flag;
endfunction
When called with any argument it behaves as expected.
x = tstflag (1)
x = 1
x = tstflag ([])
x = [](0x0)
When called with no arguments, however, the return value is expanded to the
output of the flag() function which is a 64x3 matrix.
x = tstflag ()
x =
1 0 0
1 1 1
0 0 1
0 0 0
...
I understand what is happening, either the flag() function is shadowed by
the local variable or it isn't, but I wonder what Matlab does for this
corner case? I naively assumed that no input would be similar to a null
input ([]). I can always get around this by assigning a default value to
flag in the function header.
--Rik
- Expected behavior for variables which shadow function names,
Rik <=