python - Is it possible to use fortran function as its own argument? -


i wanted find value of function recursive in nature. example, consider function defined follows:

 a(m,n) = n+1 if m=0         = a(m-1,a(m-1,n)) if m not 0 

in python can write function easily:

def a(m,n):     if(m==0):         return n+1     else:         return a(m-1,a(m-1,n)) 

but not able write similar function in fortran. basic reason fortran functions not allow own arguments. there way on problem?

thanks in advance.

this should working solution problem, if compiler supports fortran 90.

  program recursivetest   implicit none   integer a,n,m    n=2   m=2   print*, a(m,n)   end    recursive function a(m,n) result (b)   implicit none    integer n,m,b,c    if (m.ne.0)           c=a(m-1,n)           b=a(m-1,c)   else           b=n+1   endif    end function 

i compiled code using ifort (intel fortran composer 2011 sp. 1) , gfortran. intel fortran compiler allow kind of definition recursive functions:

  recursive integer function a(m,n) 

or:

  integer recursive function a(m,n) 

strict fortran 77 standard not directly support recursive functions, although there ways solve problem. if use fortran 77, please tell it. can't test right , i'm not sure how works anymore.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -