[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Puzzled about scope/existence of globals
From: |
Tomer Altman |
Subject: |
Re: Puzzled about scope/existence of globals |
Date: |
Sat, 22 Nov 2003 19:17:52 -0800 (PST) |
Oh, btw those experiments were done on Octave 2.1.40.
~T
On Nov 22, 2003 at 5:26pm, Glenn Golden wrote:
gdg >Date: Sat, 22 Nov 2003 17:26:02 -0700
gdg >From: Glenn Golden <address@hidden>
gdg >To: address@hidden
gdg >Subject: Puzzled about scope/existence of globals
gdg >Resent-Date: Sat, 22 Nov 2003 18:26:10 -0600
gdg >Resent-From: address@hidden
gdg >
gdg >
gdg >Given the function foo(), defined as
gdg >
gdg > function foo()
gdg > global g;
gdg > exist("g", "var")
gdg > endfunction
gdg >
gdg >I found the following to be surprising:
gdg >
gdg > 1> foo
gdg > ans = 0 # ok
gdg >
gdg > 2> global g
gdg >
gdg > 3> g.barf = 1;
gdg >
gdg > 4> foo
gdg > ans = 1 # ok
gdg >
gdg > 5> clear g
gdg >
gdg > 6> whos g
gdg > # ok
gdg > 7> foo
gdg > ans = 1 # huh?
gdg >
gdg >Perhaps this is expected behavior, but I don't understand it.
gdg >Can someone explain the rules regarding scope and existence
gdg >of globals in a circumstance like this?
gdg >
gdg >Thanks,
gdg >
gdg >- Glenn
gdg >
gdg >
gdg >
gdg >-------------------------------------------------------------
gdg >Octave is freely available under the terms of the GNU GPL.
gdg >
gdg >Octave's home on the web: http://www.octave.org
gdg >How to fund new projects: http://www.octave.org/funding.html
gdg >Subscription information: http://www.octave.org/archive.html
gdg >-------------------------------------------------------------
gdg >
gdg >
-------------------------------------------------------------
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
-------------------------------------------------------------
Re: Puzzled about scope/existence of globals,
Tomer Altman <=