File: recursion_02.f90

package info (click to toggle)
lfortran 0.59.0-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 56,736 kB
  • sloc: cpp: 168,052; f90: 74,272; python: 17,537; ansic: 7,705; yacc: 2,345; sh: 1,334; fortran: 895; makefile: 37; javascript: 15
file content (53 lines) | stat: -rw-r--r-- 799 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
module recursion_02
implicit none

contains


integer function solver(f, iter)
interface
    integer function f()
    end function
end interface
!procedure(f_type) :: f
integer, intent(in) :: iter
integer f_val
f_val = f()
print *, "before:", f_val
solver = sub1(2, iter-1)
!solver = sub1(2, iter-1) + f()
f_val = f()
print *, "after:", f_val
end function


integer function sub1(y, iter)
integer, intent(in):: y, iter
integer x
integer tmp
x = y
print *, "in sub1"
if (iter == 1) then
    sub1 = 1
    return
end if
tmp = getx()
sub1 = solver(getx, iter)
contains

    integer function getx()
    print *, "x in getx", x
    getx = x
    end function

end function

end module recursion_02

program main
use recursion_02
implicit none
integer :: r
r = sub1(3, 3)
print *, "r =", r
end program main