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

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

[Octave-bug-tracker] [bug #34814] persistent variables in private functi


From: Patrick Gosling
Subject: [Octave-bug-tracker] [bug #34814] persistent variables in private functions aren't persistent
Date: Sun, 13 Nov 2011 21:39:12 +0000
User-agent: Mozilla/5.0 (X11; Linux i686; rv:7.0.1) Gecko/20100101 Firefox/7.0.1

URL:
  <http://savannah.gnu.org/bugs/?34814>

                 Summary: persistent variables in private functions aren't
persistent
                 Project: GNU Octave
            Submitted by: jpmg
            Submitted on: Sun 13 Nov 2011 21:39:11 GMT
                Category: Interpreter
                Severity: 3 - Normal
                Priority: 5 - Normal
              Item Group: Other
                  Status: None
             Assigned to: None
         Originator Name: 
        Originator Email: 
             Open/Closed: Open
         Discussion Lock: Any
                 Release: 3.4.3
        Operating System: GNU/Linux

    _______________________________________________________

Details:

If a function in a private directory has a local variable declared
"persistent", then it isn't as persistent as it should be.

If the function is called multiple times within a calling function, then
persistence of the variable will be observed.

But if the outer function is called multiple times, the variable will be
re-initialised on the first occasion that the inner function is called within
each call of the outer function.

So, if I create ./private/f.m containing


function ret = f(a)
   persistent foo = 0;
   ret = a + foo;
   foo++;
endfunction


and additionally create ./testit.m containing


function testit(a)
   f(a)
   f(a)
endfunction


then if in octave I run 


testit(2)
testit(5)


I will get the result


2
3
5
6


whereas I would expect to get (and _would_ get if f() wasn't private, but was
in the current directory),


2
3
7
8


I can't see any good justification for this non-orthogonality - persistence
shouldn't become temporary just because a function is private, surely?  But
before I start poking at the code to see if I can see an obvious fix, is there
a reason I haven't thought of for this behaviour?





    _______________________________________________________

Reply to this item at:

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

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

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