help-octave
[Top][All Lists]
Advanced

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

Re: global variable question


From: taltman
Subject: Re: global variable question
Date: Thu, 11 Dec 2003 23:08:59 +0000 (UTC)

What are persistent variables? Where can I learn more about them?

~Tomer



On Dec 11, 2003 at 5:22am, Paul Kienzle wrote:

pkienz >Date: Thu, 11 Dec 2003 05:22:31 -0500
pkienz >From: Paul Kienzle <address@hidden>
pkienz >To: John W. Eaton <address@hidden>
pkienz >Cc: Geraint Paul Bevan <address@hidden>,
pkienz >     help-octave <address@hidden>
pkienz >Subject: Re: global variable question
pkienz >Resent-Date: Thu, 11 Dec 2003 04:22:49 -0600
pkienz >Resent-From: address@hidden
pkienz >
pkienz >
pkienz >On Dec 8, 2003, at 10:31 AM, John W. Eaton wrote:
pkienz >
pkienz >> On  8-Dec-2003, Geraint Paul Bevan <address@hidden> wrote:
pkienz >>
pkienz >> | Upgrading to 2.1.50 doesn't fix the problem with subsequent global
pkienz >> | declarations
pkienz >> |
pkienz >> | GNU Octave, version 2.1.50 (i386-pc-linux-gnu).
pkienz >> |
pkienz >> | octave:1> global n = 10
pkienz >> | octave:2> n
pkienz >> | n = 10
pkienz >> | octave:3> global n = 100
pkienz >> | octave:4> n
pkienz >> | n = 10
pkienz >>
pkienz >> There is nothing to fix.  As I said before, this behavior is
pkienz >> intentional, though perhaps Octave should print a warning for
pkienz >> subsequent initializations in global statements.
pkienz >
pkienz >If octave did print a warning, then the following couldn't be used:
pkienz >
pkienz >    function myfunc()
pkienz >       global myfunc_val = 'default value';
pkienz >       printf("myfunc_val is %s", myfunc_val);
pkienz >    endfunction
pkienz >
pkienz >Incidentally, I stopped using globals for edit.m because
pkienz >global variables get saved automatically whenever you save
pkienz >a variable to a file.  Is there a way to suppress this?
pkienz >
pkienz >Instead I use persistent variables, and provide a calling sequence
pkienz >to update them:
pkienz >
pkienz >    function edit(file,state)
pkienz >       persistent FUNCTION_EDITOR = [EDITOR, " %s"];
pkienz >       ...
pkienz >       if (nargin == 2)
pkienz >          switch file
pkienz >          case 'EDITOR', FUNCTION_EDITOR=state;
pkienz >          ...
pkienz >          end
pkienz >          return
pkienz >      end
pkienz >      ...
pkienz >    endfunction
pkienz >
pkienz >Paul Kienzle
pkienz >address@hidden
pkienz >
pkienz >
pkienz >
pkienz >-------------------------------------------------------------
pkienz >Octave is freely available under the terms of the GNU GPL.
pkienz >
pkienz >Octave's home on the web:  http://www.octave.org
pkienz >How to fund new projects:  http://www.octave.org/funding.html
pkienz >Subscription information:  http://www.octave.org/archive.html
pkienz >-------------------------------------------------------------
pkienz >
pkienz >



-------------------------------------------------------------
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]