[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Octave-bug-tracker] [bug #57256] Using global variable in nested functi
From: |
Marc Repnow |
Subject: |
[Octave-bug-tracker] [bug #57256] Using global variable in nested function makes variable disappear in parent function |
Date: |
Mon, 18 Nov 2019 08:07:20 -0500 (EST) |
User-agent: |
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Firefox/52.0 SeaMonkey/2.49.4 |
URL:
<https://savannah.gnu.org/bugs/?57256>
Summary: Using global variable in nested function makes
variable disappear in parent function
Project: GNU Octave
Submitted by: qx1147
Submitted on: Mon 18 Nov 2019 01:07:18 PM UTC
Category: Interpreter
Severity: 3 - Normal
Priority: 5 - Normal
Item Group: Unexpected Error
Status: None
Assigned to: None
Originator Name:
Originator Email:
Open/Closed: Open
Discussion Lock: Any
Release: 5.1.0
Operating System: Any
_______________________________________________________
Details:
Calling the following demo function fails with an "'s' undefined near line 5"
error, so calling the nested() function, which accesses the global variable
's' (with or without declaring it "global"), makes the global variable 's'
disappear in demo() thereafter. I can bring 's' back, however, with another
"global" statement.
The same code works fine in Octave 4.2.1.
function demo()
global s=99
nested();
# global s % needed for making 's' accessible again.
fprintf('demo(): s=%d.\n', s);
function nested()
fprintf('nested(): s=%d.\n', s);
end
end
Output:
>> demo
nested(): s=99.
error: 's' undefined near line 5 column 32
error: called from
demo at line 5 column 5
Output with old Octave, or when using the second "global" statement:
>> demo
nested(): s=99.
demo(): s=99.
_______________________________________________________
Reply to this item at:
<https://savannah.gnu.org/bugs/?57256>
_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/
- [Octave-bug-tracker] [bug #57256] Using global variable in nested function makes variable disappear in parent function,
Marc Repnow <=