Re: writing recursive function ...

From: Ufuk Utku Turuncoglu (BE) <u.utku.turuncoglu_at_nyahnyahspammersnyahnyah>
Date: Mon Aug 08 2011 - 08:22:21 MDT

Hi,

Thanks Mary. I work around it by putting a while loop but i will try to
convert it to a recursive one. Somehow, the recursive code fails when it
is checking the types. Putting some extra check for variable types is
good idea. Maybe it works. Anyway, thanks for your help.

Regards,

--ufuk

On 8/8/11 4:08 PM, Mary Haley wrote:
> Hi Ufuk,
>
> I was going to write and say that recursion doesn't work in NCL, because I thought NCL had a strict rule about a function being defined completely before you could call it.
>
> But, this small test worked for me:
>
> function factorial(n[1]:integer)
> begin
> if (n .le. 1) then
> return(1)
> else
> return(n * factorial(n-1))
> end if
> end
>
> ;---main code
> begin
> n = 10
> x = factorial(n)
> print("factorial(" + n + ") = " + x)
> end
>
>
> You may need to check the types of your variables and attributes to make sure you are not mixing types or dimension sizes.
>
> --Mary
>
>
> On Aug 7, 2011, at 10:42 AM, Ufuk Utku Turuncoglu (BE) wrote:
>
>> Hi All,
>>
>> I just want to write a recursive function in NCL. Does NCL support
>> recursive functions? To test it i wrote a function that calls itself but
>> it gives following error,
>>
>> fatal:Illegal right-hand side type for assignment
>>
>> Note that the function runs successfully without implementation of
>> recursion. What do you suggest?
>>
>> Regards,
>>
>> --ufuk
>> _______________________________________________
>> ncl-talk mailing list
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Mon Aug 8 08:22:34 2011

This archive was generated by hypermail 2.1.8 : Fri Aug 12 2011 - 11:48:30 MDT