[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
A global variable, "x", in traditional mode gives exist("x") == 1 even
From: |
John W. Eaton |
Subject: |
A global variable, "x", in traditional mode gives exist("x") == 1 even in a function where x is not defined. |
Date: |
Tue, 2 Mar 1999 01:41:31 -0600 (CST) |
On 25-Feb-1999, Mats Jansson <address@hidden> wrote:
| Bug report for Octave 2.0.13.90 configured for i386-redhat-linux-gnu
|
| Description:
| -----------
| In traditional mode (initialize_global_variables = 1):
| If a global variable is defined (eg. "x"), exist("x") returns 1 even in
| a function where x is not defined.
|
|
| Repeat-By:
| ---------
|
| address@hidden demo]$ octave --traditional
| Octave, version 2.0.13.90 (i386-redhat-linux-gnu).
| Copyright (C) 1996, 1997, 1998 John W. Eaton.
| This is free software with ABSOLUTELY NO WARRANTY.
| For details, type `warranty'.
|
| >> type problem
| problem is the function defined from: /home/mj/fest/demo/problem.m
|
| function problem(x)
| exist("x")
| if exist("x") == 1, disp(x), endif
| endfunction
| >> problem
| ans = 0
| >> global x
| >> problem
| ans = 1
| error: `x' undefined near line 3 column 28
| error: evaluating expression near line 3, column 28
| error: evaluating argument list element number 1
| error: evaluating index expression near line 3, column 23
| error: evaluating if command near line 3, column 3
| error: called from `problem' in file `/home/mj/fest/demo/problem.m'
| >> clear
| >> initialize_global_variables = 0
| initialize_global_variables = 0
| >> problem
| ans = 0
| >> global x
| >> problem
| ans = 0
| >> exit
| address@hidden demo]$
Please try the following patch. I hope it doesn't break anything
else.
Thanks,
jwe
Tue Mar 2 01:36:29 1999 John W. Eaton <address@hidden>
* variables.cc (Fexist): If a variable isn't defined, only go on
to look for a global by the same name if we are at the top level.
*** src/variables.cc~ Tue Jun 23 15:49:46 1998
--- src/variables.cc Tue Mar 2 01:35:54 1999
***************
*** 354,360 ****
}
symbol_record *sr = curr_sym_tab->lookup (symbol_name, 0, 0);
! if (! (sr && sr->is_defined ()))
sr = global_sym_tab->lookup (symbol_name, 0, 0);
retval = 0.0;
--- 354,361 ----
}
symbol_record *sr = curr_sym_tab->lookup (symbol_name, 0, 0);
! if (! (sr && (sr->is_defined ()
! || (curr_sym_tab != top_level_sym_tab))))
sr = global_sym_tab->lookup (symbol_name, 0, 0);
retval = 0.0;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- A global variable, "x", in traditional mode gives exist("x") == 1 even in a function where x is not defined.,
John W. Eaton <=