Created
September 29, 2020 21:14
-
-
Save JeffIrwin/28b26ca8e69d49a0ddb558ae3a319889 to your computer and use it in GitHub Desktop.
Hot take: an array is a function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module mymodule | |
integer, parameter :: n = 6 | |
integer, parameter :: myarray(n) = [1, 1, 2, 3, 5, 8] | |
contains | |
integer function myfunc(input) | |
integer :: input, i, j, k | |
myfunc = 1 | |
i = 1 | |
j = 1 | |
do k = 1, input - 2 | |
myfunc = i + j | |
i = j | |
j = myfunc | |
end do | |
end function myfunc | |
end module mymodule | |
program array | |
use mymodule | |
integer :: i | |
write(*,*) '=========================' | |
write(*,*) ' array , function' | |
write(*,*) '=========================' | |
do i = 1, n | |
write(*,*) myarray(i), ',', myfunc(i) | |
end do | |
write(*,*) '=========================' | |
end program array | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment