comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Recursive function/procedure
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: Recursive function/procedure [message #15133] Sat, 24 April 1999 00:00
Brian Jackel is currently offline  Brian Jackel
Messages: 34
Registered: January 1998
Member
Tri VU KHAC wrote:
>
> Hi folks,
>
> I did not see anyone tells about this problem:
>
> function AAA, a,b,C=c,D=d
> return, AAA(a, b, C=c, D=d)
> end
>
> Creating this function is very stupid. But the problem is not in this
> function.
> Writing this function is correct, I think. But if you compile this, the
> compilator says there is a syntax error:
>
> return, AAA(a, b, C=c, D=d)
> ^
> Syntax error.
>
> However, if I do a litle strick:
> +remove the two last parameters (c,d)
> +compile this function (no error here)
> +add the two last parameters (c,d)
> +re-compile this function - well, it passes with no error.
>
> Now this function already works very well.
> Could you tell me why ? How to avoid this stupid doing ?
> Best regards,

Take a look at the FORWARD_FUNCTION command.


--
Brian Jackel
Re: Recursive function/procedure [message #15136 is a reply to message #15133] Sat, 24 April 1999 00:00 Go to previous message
VU KHAC Tri is currently offline  VU KHAC Tri
Messages: 25
Registered: March 1999
Junior Member
Hi folks,

I did not see anyone tells about this problem:

function AAA, a,b,C=c,D=d
return, AAA(a, b, C=c, D=d)
end

Creating this function is very stupid. But the problem is not in this
function.
Writing this function is correct, I think. But if you compile this, the
compilator says there is a syntax error:

return, AAA(a, b, C=c, D=d)
^
Syntax error.

However, if I do a litle strick:
+remove the two last parameters (c,d)
+compile this function (no error here)
+add the two last parameters (c,d)
+re-compile this function - well, it passes with no error.

Now this function already works very well.
Could you tell me why ? How to avoid this stupid doing ?
Best regards,

Tri.


Tri VU KHAC wrote:

> Hi folks,
> How to write a recursive function/procedure ?
> What are programming problems of this technique in IDL ?
> Thanks for help.
> Best regards,
> Tri
Re: Recursive function/procedure [message #15150 is a reply to message #15133] Fri, 23 April 1999 00:00 Go to previous message
Martin Schultz is currently offline  Martin Schultz
Messages: 515
Registered: August 1997
Senior Member
Tri VU KHAC wrote:
>
> Hi folks,
> How to write a recursive function/procedure ?
> What are programming problems of this technique in IDL ?
> Thanks for help.
> Best regards,
> Tri

since the first question has been answered let me address the second
one:
as always with recursive procedures, you must take care not to run into
infinite loops (and there is some limitation as to how many recursions
you can make although I don't know the number now). Hence, a "safe"
recursive procedure would look like this:

pro recurse,level

MAX_LEVEL = 1000 ; or whatever is reasonable

if (n_elements(level) eq 0) then level = 0 ; main entry level
if (level gt MAX_LEVEL) then begin
message,'Maximum number of iterations exceeded!' ; optional +
,/Continue
return
endif

; *** do your stuff here

recurse,level+1

; *** do more stuff here

return
end



Regards,
Martin.

--
------------------------------------------------------------ -------
Dr. Martin Schultz
Department for Engineering&Applied Sciences, Harvard University
109 Pierce Hall, 29 Oxford St., Cambridge, MA-02138, USA

phone: (617)-496-8318
fax : (617)-495-4551

e-mail: mgs@io.harvard.edu
Internet-homepage: http://www-as.harvard.edu/people/staff/mgs/
------------------------------------------------------------ -------
Re: Recursive function/procedure [message #15157 is a reply to message #15150] Fri, 23 April 1999 00:00 Go to previous message
ronn is currently offline  ronn
Messages: 123
Registered: April 1999
Senior Member
In article <372050FC.85669B9@info.fundp.ac.be>,
Tri VU KHAC <tvk@info.fundp.ac.be> wrote:
> Hi folks,
> How to write a recursive function/procedure ?
> What are programming problems of this technique in IDL ?
> Thanks for help.
> Best regards,
> Tri
>
>
Tri,

I have a couple of sections of using recursion (procedures, functions and
methods!) in my new book. Check out my web site at www.rlkling.com for
details.

-Ronn

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
Re: Recursive function/procedure [message #15160 is a reply to message #15150] Fri, 23 April 1999 00:00 Go to previous message
mgs is currently offline  mgs
Messages: 144
Registered: March 1995
Senior Member
In article <7fpsdj$pel$1@nnrp1.dejanews.com>, wbiagiot@suffolk.lib.ny.us wrote:

> Tri VU KHAC <tvk@info.fundp.ac.be> wrote:
>> Hi folks,
>> How to write a recursive function/procedure ?
>> What are programming problems of this technique in IDL ?
>> Thanks for help.
>> Best regards,
>> Tri
>>

I have a recursive program on my site at http://www.ivsoftware.com/.
Select the IDL Code link and look for bitex.

--
Mike Schienle Interactive Visuals, Inc.
mgs@ivsoftware.com Remote Sensing and Image Processing
http://www.ivsoftware.com/ Analysis and Application Development
Re: Recursive function/procedure [message #15164 is a reply to message #15150] Fri, 23 April 1999 00:00 Go to previous message
wbiagiot is currently offline  wbiagiot
Messages: 59
Registered: January 1999
Member
Tri VU KHAC <tvk@info.fundp.ac.be> wrote:
> Hi folks,
> How to write a recursive function/procedure ?
> What are programming problems of this technique in IDL ?
> Thanks for help.
> Best regards,
> Tri
>
>

Hi Tri,

Well, writing a recursive routine is pretty much the same in any language.
Here's a quick example:

PRO My_routine, My_mode_parameter

CASE (My_mode_parameter) OF
0: BEGIN ; Perform all 3 actions
My_routine, 1
My_routine, 2
My_routine, 3
END
1: BEGIN
<action 1>
END
2: BEGIN
<action 2>
END
3: BEGIN
<action 3>
END
ELSE:
ENDCASE

END ; PRO


Hope this helps.

-Bill

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Recursive function/procedure
Next Topic: Re: Mac SEND_EVENT

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 15:27:21 PDT 2025

Total time taken to generate the page: 0.00749 seconds