[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Octave-bug-tracker] [bug #35881] clear all removes subfunctions
From: |
John W. Eaton |
Subject: |
[Octave-bug-tracker] [bug #35881] clear all removes subfunctions |
Date: |
Tue, 03 May 2016 14:38:24 +0000 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:44.0) Gecko/20100101 Firefox/44.0 Iceweasel/44.0 |
Follow-up Comment #14, bug #35881 (project octave):
If "clear all" is called within a function, does it only work within the
current function scope or does it also clear variables defined in the
top-level workspace and other functions (not the one currently executing or
its sub and nested functions)?
Here is how I would test for this behavior. Define the following functions:
function f1 ()
clear all
end
function f2 ()
persistent p
if (isempty (p))
disp ('p is not yet initialized')
p = 1;
else
fprintf ('p is initialized with value p = %d', p)
end
end
Then execute
f2
f2
f1
f2
You should see the message about p not initialized, then that it is
initialized with value 1, then on the third call to f2, what happens? Does
the persistent variable need to be initialized? If so, the "clear all" inside
f1 must have also cleared f2. Otherwise, I would guess that the scope of
"clear" is limited to the scope where it is executed, which is behavior that
makes more sense anyway.
Oh, after writing all of that, I now see that I asked this question previously
and apparently the behavior I was hoping for is (once again!) NOT how Matlab
behaves?!?
_______________________________________________________
Reply to this item at:
<http://savannah.gnu.org/bugs/?35881>
_______________________________________________
Message sent via/by Savannah
http://savannah.gnu.org/
- [Octave-bug-tracker] [bug #35881] clear all removes subfunctions, Julien Bect, 2016/05/03
- [Octave-bug-tracker] [bug #35881] clear all removes subfunctions, Julien Bect, 2016/05/03
- [Octave-bug-tracker] [bug #35881] clear all removes subfunctions, Julien Bect, 2016/05/03
- [Octave-bug-tracker] [bug #35881] clear all removes subfunctions, Julien Bect, 2016/05/03
- [Octave-bug-tracker] [bug #35881] clear all removes subfunctions, sergey plotnikov, 2016/05/03
- [Octave-bug-tracker] [bug #35881] clear all removes subfunctions, Julien Bect, 2016/05/03
- [Octave-bug-tracker] [bug #35881] clear all removes subfunctions, Julien Bect, 2016/05/03
- [Octave-bug-tracker] [bug #35881] clear all removes subfunctions,
John W. Eaton <=
- [Octave-bug-tracker] [bug #35881] clear all removes subfunctions, sergey plotnikov, 2016/05/03
- [Octave-bug-tracker] [bug #35881] clear all removes subfunctions, Julien Bect, 2016/05/03
- [Octave-bug-tracker] [bug #35881] clear all removes subfunctions, John W. Eaton, 2016/05/03
- [Octave-bug-tracker] [bug #35881] clear all removes subfunctions, Rik, 2016/05/03
- [Octave-bug-tracker] [bug #35881] clear all removes subfunctions, Julien Bect, 2016/05/03
- [Octave-bug-tracker] [bug #35881] clear all removes subfunctions, Rik, 2016/05/03
- [Octave-bug-tracker] [bug #35881] clear all removes subfunctions, Julien Bect, 2016/05/03