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

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

[Octave-bug-tracker] [bug #35881] clear all removes subfunctions


From: Julien Bect
Subject: [Octave-bug-tracker] [bug #35881] clear all removes subfunctions
Date: Tue, 03 May 2016 13:17:42 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0

Follow-up Comment #10, bug #35881 (project octave):

Yet another follow-up to comment #8:

What I said there applies direcly to "clear functions", or to "clear MyFunc"
(where MyFunc is the name of the current function) but the case of "clear all"
requires a more detailed explanation.

We must first clarify what "clearing a function" actually means. I will assume
that it simply means "clearing the persistent variables inside the function"
(if not mlock'ed). It might mean something more in Octave internally, such as
removing the function definition from memory, but from a user's perspective
(mine at least) this is what it looks like.

Then, in my understanding, a persistent living inside MyFunc is cleared by a
call to "clear all" inside MyFunc, not because the function is cleared (the
doc says that it isn't), but simply becaused "clear all" also removes all
variables from the current workspace.

Let me illustrate (R2016a):

>> type test_clear_inside_function.m

function test_clear_inside_function (flag)
persistent a
if isempty (a), a = 1; end
subf ();  fprintf ('a=%dn', a);
switch flag
    case 0
        clear subf
    case 1
        clear functions
    case 2
        clear all
end
subf ();  fprintf ('a=%dn', a);
fprintf ('------nn');
end

function subf ()
persistent x
fprintf ('subf: ');
if isempty (x)
  x = 1;
  fprintf ('INIT, ');
end
end

>> clear all;  test_clear_inside_function (0)
subf: INIT, a=1
subf: a=1
------

>> clear all;  test_clear_inside_function (1)
subf: INIT, a=1
subf: a=1
------

>> clear all;  test_clear_inside_function (2)
subf: INIT, a=1
subf: Reference to a cleared variable a.
Error in test_clear_inside_function (line 13)
subf ();  fprintf ('a=%dn', a); 



    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?35881>

_______________________________________________
  Message posté via/par Savannah
  http://savannah.gnu.org/




reply via email to

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