Re: writing recursive function ...

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Mon Aug 08 2011 - 08:08:44 MDT

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:08:51 2011

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