From bug-octave-request at bevo dot che dot wisc dot edu Tue Dec 17 18:34:14 2002 Subject: Variables not being cleared From: "John W. Eaton" To: Andrew Jackson Cc: bug-octave at bevo dot che dot wisc dot edu Date: Tue, 17 Dec 2002 18:33:52 -0600 On 13-Dec-2002, Andrew Jackson wrote: | I'm not certain this is a bug, but it is certainly different behaviour | between 2.1.36 and 2.1.40. | | I have two script files, one calling the other. The first sets up variables | that I don't want to have to enter every time I call the second script. The | second does an exist() on the variables to see if I need to enter them. | | The problem arises that having run the scripts once despite calling clear | and checking the existance of the variables manually with who and exist | (they have gone) when I rerun the script the variables, which are all | defined as globals magically reappear with their previous values. | | Clear in 2.1.36 works and the variable *really* are cleared, whereas in | 2.1.40 they only appear to have been cleared. | | An example: | ---Script A--- | global A B C | A = 1; | B = 2; | scriptb | ---End Script--- | | ---Script B--- | global A B C | if (!exist('A')) | A = input('A: '); | endif | if (!exist('B')) | B = input('B: '); | endif | if (!exist('C')) | C = input('C: '); | endif | A | B | C | ---End Script--- | | The octave session : | | octave:1> scripta | C: 12 | A = 1 | B = 2 | C = 12 | octave:2> clear | octave:3> who -variables | octave:4> exist('A') | ans = 0 | octave:5> exist('B') | ans = 0 | octave:6> exist('C') | ans = 0 | octave:7> scripta | A = 1 | B = 2 | C = 12 | octave:8> | | Whereas 2.1.36 asks for C on the second run. With 2.1.40, you need to use either clear global %% Matlab compatible or clear -global to clear global variables. Unfortunately, there is an off-by-one error that prevents the "-global" option from working. The patch below should fix that problem. Thanks, jwe 2002-12-17 John W. Eaton * variables.cc (Fclear): Fix off-by-one error. Index: src/variables.cc =================================================================== RCS file: /usr/local/cvsroot/octave/src/variables.cc,v retrieving revision 1.236 diff -u -r1.236 variables.cc --- src/variables.cc 3 Dec 2002 19:48:57 -0000 1.236 +++ src/variables.cc 18 Dec 2002 00:32:49 -0000 at @ -1700,7 +1700,7 @@ break; } - if (idx < argc) + if (idx <= argc) { if (! have_dash_option) { ------------------------------------------------------------- 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 -------------------------------------------------------------