recursive functions? [message #21526] |
Thu, 31 August 2000 08:48  |
Nando Iavarone
Messages: 48 Registered: December 1998
|
Member |
|
|
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
Hi all,
<br>I wrote a recursive function, but something does not work.
<br>The example reported is the skeleton of the function.
<p>In this version:
<p>
function recFun, var1, var2
<br>
print, var1, var2
<br>
err = recFun($
<br>
string(var1)+'.Prrrr', $
<br>
string(var2)+'.Prrrr')
<br>
return, 0
<br>
end;
<br>
<p>
function recFunTest, var1, var2
<br>
err = recFun($
<br>
string(var1)+'.Prrrr', $
<br>
string(var2)+'.Prrrr')
<br>
return, err
<br>
end;
<br>
<br>
<br>
<p>if the source file is recFun.pro,
<br>IDL shows:
<p>ENVI> .compile recFun
<br>% Compiled module: RECFUN.
<br>% Compiled module: RECFUNTEST.
<br>ENVI> err=recFunTest(12,15)
<br> 12.Prrrr
15.Prrrr
<br>% Variable is undefined: RECFUN.
<br>% Execution halted at: RECFUN & ;nbsp; & ;nbsp;
5
<br> /home/nando/InPhase/procedureDiProva/recFun.pro
<br> %   ;   ;   ;
RECFUNTEST 19
<br> /home/nando/InPhase/procedureDiProva/recFun.pro
<br> %   ;   ;   ;
$MAIN$
<br>ENVI>
<br>
<br>
<br>
<p>If the file is modified as:
<p>
function recFunTest, var1, var2
<p>
print, var1, var2
<br>
err = recFuntest($
<br>
string(var1)+'.Prrrr', $
<br>
string(var2)+'.Prrrr')
<br>
<br>
return, err
<br>
end;
<br>
<p>the recursive function works.
<p>Am I missing something in the first case?
<br>Why it does not work?
<p>Thank you.
<pre>--
Nando Iavarone
Advanced Computer System - SPACE DIVISION
via Lazzaro Belli, 23
00040 Frascati - RM
Tel: +39-6-944091 (switchboard)
9440968 (direct)
E-mail:
f.iavarone@acsys.it
FrdndVrn@altavista.net</pre>
</html>
|
|
|
Re: recursive functions? [message #21596 is a reply to message #21526] |
Fri, 01 September 2000 02:57  |
Nando Iavarone
Messages: 48 Registered: December 1998
|
Member |
|
|
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
David Fanning wrote:
<blockquote TYPE=CITE>....I have to
<br>warn you, however, that with this line your test program
<br>will run forever!</blockquote>
I know, I know.
<br>It was to show the skeleton of the original function without to show
it entirely.
<br>I found already the solution on manual and on........ your www page
:o(
<br>Maybe as first resource I'd search on your web pages.
<p>Have you idea of the difference between the two versions of the test
code?
<br>I think it is important to understand how IDL works.
<p>Bye.
<pre></pre>
<pre>--
Nando Iavarone
Advanced Computer System - SPACE DIVISION
via Lazzaro Belli, 23
00040 Frascati - RM
Tel: +39-6-944091 (switchboard)
9440968 (direct)
E-mail:
f.iavarone@acsys.it
FrdndVrn@altavista.net</pre>
</html>
|
|
|
Re: recursive functions? [message #21621 is a reply to message #21526] |
Thu, 31 August 2000 09:30  |
Nando Iavarone
Messages: 48 Registered: December 1998
|
Member |
|
|
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
Nando Iavarone wrote:
<blockquote TYPE=CITE>I don't remember well, but 5.3 would have a mechanism
in compiling to avoid this.</blockquote>
<p><br>I look better in the manual and:
<br>there exist the FORWARD_FUNCTION statement.
<p>I answer me. Ohhhh.
<p>The problem about the difference about the two code fragment remains?
<br>Why don't they work in the same manner?
<p>Cheers,
<br>
Nando.
<pre>--
Nando Iavarone
Advanced Computer System - SPACE DIVISION
via Lazzaro Belli, 23
00040 Frascati - RM
Tel: +39-6-944091 (switchboard)
9440968 (direct)
E-mail:
f.iavarone@acsys.it
FrdndVrn@altavista.net</pre>
</html>
|
|
|
Re: recursive functions? [message #21622 is a reply to message #21526] |
Thu, 31 August 2000 08:37  |
davidf
Messages: 2866 Registered: September 1996
|
Senior Member |
|
|
Nando Iavarone (f.iavarone@acsys.it) writes:
>
> I don't remember well, but 5.3 would have a mechanism in compiling to
> avoid this.
> Is it true?
Forward_Function RecFun
As the first line in RecFun will do it. I have to
warn you, however, that with this line your test program
will run forever! You might want to give this some thought. :-)
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
|
|
|
Re: recursive functions? [message #21624 is a reply to message #21526] |
Thu, 31 August 2000 09:08  |
Nando Iavarone
Messages: 48 Registered: December 1998
|
Member |
|
|
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
Nando Iavarone wrote:
<blockquote TYPE=CITE>ENVI> .compile recFun
<br>% Compiled module: RECFUN.
<br>% Compiled module: RECFUNTEST.
<br>ENVI> err=recFunTest(12,15)
<br> 12.Prrrr
15.Prrrr
<br>% Variable is undefined: RECFUN.
<br>% Execution halted at: RECFUN & ;nbsp; & ;nbsp;
5
<br> /home/nando/InPhase/procedureDiProva/recFun.pro
<br> %   ;   ;   ;
RECFUNTEST 19
<br> /home/nando/InPhase/procedureDiProva/recFun.pro
<br> %   ;   ;   ;
$MAIN$
<br>ENVI>
<br>
<br>
<br> </blockquote>
it seems that the first time IDL 'compile' recFun function,
<br>it consider recFun (in the code it is a function) a variable and on
run it does not find it.
<br>if I recompile the source, recFun is now in the table of the functions
and it works.
<br>as a workaround I compile the source twice and it works, but I don't
like this.
<br>I am sure there is something I have not considered.
<p>I don't remember well, but 5.3 would have a mechanism in compiling to
avoid this.
<br>Is it true?
<br>Oh oh........ but I am working with 5.2 (to use ENVI 3.2).
<p>Bye.
<br>
<pre>--
Nando Iavarone
Advanced Computer System - SPACE DIVISION
via Lazzaro Belli, 23
00040 Frascati - RM
Tel: +39-6-944091 (switchboard)
9440968 (direct)
E-mail:
f.iavarone@acsys.it
FrdndVrn@altavista.net</pre>
</html>
|
|
|