help-octave
[Top][All Lists]
Advanced

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

Re: global variable question


From: Paul Kienzle
Subject: Re: global variable question
Date: Thu, 11 Dec 2003 05:22:31 -0500


On Dec 8, 2003, at 10:31 AM, John W. Eaton wrote:

On  8-Dec-2003, Geraint Paul Bevan <address@hidden> wrote:

| Upgrading to 2.1.50 doesn't fix the problem with subsequent global
| declarations
|
| GNU Octave, version 2.1.50 (i386-pc-linux-gnu).
|
| octave:1> global n = 10
| octave:2> n
| n = 10
| octave:3> global n = 100
| octave:4> n
| n = 10

There is nothing to fix.  As I said before, this behavior is
intentional, though perhaps Octave should print a warning for
subsequent initializations in global statements.

If octave did print a warning, then the following couldn't be used:

   function myfunc()
      global myfunc_val = 'default value';
      printf("myfunc_val is %s", myfunc_val);
   endfunction

Incidentally, I stopped using globals for edit.m because
global variables get saved automatically whenever you save
a variable to a file.  Is there a way to suppress this?

Instead I use persistent variables, and provide a calling sequence
to update them:

   function edit(file,state)
      persistent FUNCTION_EDITOR = [EDITOR, " %s"];
      ...
      if (nargin == 2)
         switch file
         case 'EDITOR', FUNCTION_EDITOR=state;
         ...
         end
         return
     end
     ...
   endfunction

Paul Kienzle
address@hidden



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

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