From bug-octave-request at che dot utexas dot edu Wed Oct 13 15:23:39 1993 Subject: exist bug? From: donoho at gandalf dot Berkeley dot EDU (David Donoho) To: bug-octave at che dot utexas dot edu Date: Wed, 13 Oct 93 13:22:20 PDT For a library of signal processing stuff in matlab I developed tools which use the idiom if exist('n')==0, n = input('n?'); end to set variables which are so far unset. These don't seem to work in OCTAVE. Example: %======= TrialSignals.m ========= % TrialSignals: generate various signals for % time-frequency analysis ... % if(exist('n') == 0), n = input('signal length ?') end t = (1:n) ./n; % Sinusoids HiSine = sin( pi * (n * .6902) .* t); LoSine = sin( pi * (n * .3333) .* t); % Chirps LinChirp = sin(250 .* t .^2); TwoChirp = sin(250 .* t .^2) + sin(100 .* t .^2); QuadChirp = sin( 100 .* (2 .* t) .^3); % Singularities Leopold = (t == floor(.37 * n)/n); % Kronecker Ramp = t - (t >= .37); Crease = exp(-4*abs(t - .37)); Cusp = sqrt(abs(t - .37)); k = floor(n * .37); Sing = 1 ./abs(t - (k+.5)/n); =========================================== this m-file generates the following script gandalf.donoho% octave Octave, version 0.76. Copyright (C) 1992, 1993, John W. Eaton. This is free software with ABSOLUTELY NO WARRANTY. For details, type `warranty'. octave:1> startoct LOADPATH = ~/octave:.:/lion/g/app/octave/scripts octave:2> TrialSignals error: `n' undefined near line 4 column 8 error: invalid null value in colon expression near line 4 column 7 error: evaluating assignment expression near line 4, column 3 octave:3> who octave:4> exist('n') ans = 1 octave:5> for i=1:10, exist('n'),end ans = 1 ans = 1 ans = 1 ans = 1 ans = 1 ans = 1 ans = 1 ans = 1 ans = 1 ans = 1 octave:6> who *** local symbols: i octave:7> n error: `n' undefined near line 7 column 1 octave:8> for i=1:10,exist('Beufort'), end ans = 0 ans = 0 ans = 0 ans = 0 ans = 0 ans = 0 ans = 0 ans = 0 ans = 0 ans = 0 octave:9> for i=1:10, exist('blotz'), end ans = 0 ans = 0 ans = 0 ans = 0 ans = 0 ans = 0 ans = 0 ans = 0 ans = 0 ans = 0 octave:10> exist('n') ans = 0 octave:11> TrialSignals error: `n' undefined near line 4 column 8 error: invalid null value in colon expression near line 4 column 7 error: evaluating assignment expression near line 4, column 3 octave:12> exist('n') ans = 1 octave:13> n = 2048 n = 2048 octave:14> TrialSignals octave:15> who *** local symbols: Crease HiSine LinChirp QuadChirp Sing i n Cusp Leopold LoSine Ramp TwoChirp k t octave:16> quit gandalf.donoho% ======================================================== In short, even when Octave returns an empty who, exist('n') returns 1. But sometime later, it starts to return 0. Could it be that variables which are referred to in an m-file are thought by Octave to ``exist'' from the moment the m-file is entered, even if no code referring to them has yet been processed? Could it be that if m-file execution is terminated due to error, that symbols have ghost lives that make them continue to ``exist''? Dave