[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Problem with exist
From: |
John W. Eaton |
Subject: |
Problem with exist |
Date: |
Sat, 22 Feb 2003 12:26:34 -0600 |
On 22-Feb-2003, Andy Adler <address@hidden> wrote:
| I'm having a problem with exist().
|
| If foo.m is currently loaded then
| exist('foo.anything') is true, regardless
| of whether the file exists.
|
| This is a problem, because my code does
|
| function out=foo();
| if exist('foo.mat');
| load('foo.mat');
| else
| out=calculate_out();
| save('foo.mat',out);
| end
|
| This example shows the problem
|
| $ cat > foo.m
| function x=foo(y); x=y+1; endfunction;
|
| $ octave -q
| octave:1> exist('foo')
| ans = 2
| octave:2> exist('foo.mat')
| ans = 0
| octave:3> foo(1);
| octave:4> exist('foo')
| ans = 2
| octave:5> exist('foo.mat')
| ans = 2
| octave:6> exist('foo.anything')
| ans = 2
Please try the following patch.
Thanks,
jwe
2003-02-22 John W. Eaton <address@hidden>
* variables.cc (symbol_exist): For names like foo.bar, don't omit
the part after the dot.
Index: src/variables.cc
===================================================================
RCS file: /usr/local/cvsroot/octave/src/variables.cc,v
retrieving revision 1.246
diff -u -r1.246 variables.cc
--- src/variables.cc 20 Feb 2003 20:45:49 -0000 1.246
+++ src/variables.cc 22 Feb 2003 18:19:59 -0000
@@ -559,10 +559,13 @@
if (sr && sr->is_defined ())
{
+ bool not_a_struct = struct_elts.empty ();
+ bool var_ok = not_a_struct || sr->is_map_element (struct_elts);
+
if (! retval
+ && var_ok
&& (type == "any" || type == "var")
- && sr->is_variable ()
- && (struct_elts.empty () || sr->is_map_element (struct_elts)))
+ && sr->is_user_variable ())
{
retval = 1;
}
@@ -570,21 +573,22 @@
if (! retval
&& (type == "any" || type == "builtin"))
{
- if (sr->is_builtin_function ())
+ if (not_a_struct && sr->is_builtin_function ())
{
retval = 5;
}
- else if (sr->is_builtin_variable ())
+ else if (var_ok && sr->is_builtin_variable ())
{
retval = 101;
}
- else if (sr->is_builtin_constant ())
+ else if (var_ok && sr->is_builtin_constant ())
{
retval = 102;
}
}
if (! retval
+ && not_a_struct
&& (type == "any" || type == "file")
&& (sr->is_user_function () || sr->is_dld_function ()))
{