아래처럼 부모 모듈과 각 서브모듈이 별도 파일에 있어요. 서브모듈 D에서 use 결합으로 서브모듈 C의 프로시저를 호출할 수 있나요?
(File) module root_mod
|
|—(File) submodule C
| public module procedure taskC
|
|—(File) submodule D
use submodule C ? or use root_mod:submodule C
call taskC
아래처럼 부모 모듈과 각 서브모듈이 별도 파일에 있어요. 서브모듈 D에서 use 결합으로 서브모듈 C의 프로시저를 호출할 수 있나요?
(File) module root_mod
|
|—(File) submodule C
| public module procedure taskC
|
|—(File) submodule D
use submodule C ? or use root_mod:submodule C
call taskC
Each parent module and submodule lives in a separate file, as illustrated here. Is use association a way for submodule D to invoke a procedure from submodule C?
(File) module root_mod
|
|—(File) submodule C
| public module procedure taskC
|
|—(File) submodule D
use submodule C ? or use root_mod:submodule C
call taskC
두 가지를 바꾸면 서로 호출할 수 있어요:
자식 루틴의 인터페이스를 부모 모듈에 넣으세요
모든 자식이 같은 부모 모듈에 속하므로 use는 필요 없어요
완전한 동작 예제는 다음과 같아요:
demo.f90:
module root_mod
implicit none
interface
module subroutine routine_c()
end subroutine routine_c
module subroutine routine_d()
end subroutine routine_d
end interface
end module root_mod
program demo
use root_mod
implicit none
call routine_d()
end program demo
c.f90:
submodule(root_mod) c
implicit none
contains
module subroutine routine_c
print *, "hello from routine_c"
end subroutine routine_c
end submodule c
d.f90:
submodule(root_mod) d
implicit none
contains
module subroutine routine_d
print *, "hello from routine_d"
call routine_c()
end subroutine routine_d
end submodule d
They can invoke one another after two adjustments:
Put interfaces for the child routines into the parent module
You don't need use, as every child shares that parent module
A full working example follows:
demo.f90:
module root_mod
implicit none
interface
module subroutine routine_c()
end subroutine routine_c
module subroutine routine_d()
end subroutine routine_d
end interface
end module root_mod
program demo
use root_mod
implicit none
call routine_d()
end program demo
c.f90:
submodule(root_mod) c
implicit none
contains
module subroutine routine_c
print *, "hello from routine_c"
end subroutine routine_c
end submodule c
d.f90:
submodule(root_mod) d
implicit none
contains
module subroutine routine_d
print *, "hello from routine_d"
call routine_c()
end subroutine routine_d
end submodule d
taskC를 부모 모듈에 넣으면 모든 서브모듈에서 접근할 수 있는데, 그건 제가 원하는 게 아니에요.
Putting taskC in the parent module makes it accessible from every submodule, and that isn't what I want.

Fortran의 형제 서브모듈은 서로의 존재를 몰라요. 다만 서브모듈 계층은 필요한 만큼 늘릴 수 있어요:
module root1
implicit none
...
end module root1
submodule (root1) layer1
implicit none
interface
module subroutine task1() ! visible to descendants of layer1 but not to root1
end subroutine
end interface
end submodule layer1
submodule (root1:layer1) layer2
implicit none
contains
subroutine perform_task()
call task1()
end subroutine
end submodule layer2
submodule (root1:layer1) layer3
implicit none
contains
subroutine perform_task()
call task1()
end subroutine
end submodule layer3
layer2와 layer3가 모두 perform_task를 정의한다는 점을 보세요. 형제라서 서로의 선언을 볼 수 없기 때문이에요.
Sibling Fortran submodules don't know that the others exist. The hierarchy of submodules can, however, be extended as far as you need:
module root1
implicit none
...
end module root1
submodule (root1) layer1
implicit none
interface
module subroutine task1() ! visible to descendants of layer1 but not to root1
end subroutine
end interface
end submodule layer1
submodule (root1:layer1) layer2
implicit none
contains
subroutine perform_task()
call task1()
end subroutine
end submodule layer2
submodule (root1:layer1) layer3
implicit none
contains
subroutine perform_task()
call task1()
end subroutine
end submodule layer3
Observe that both layer2 and layer3 define perform_task, because as siblings they cannot see one another's declarations.
GDScript에서 enum을 이렇게 선언했어요: 가능한 모든 변형을 나열하지 않고 enum 변형을 무작위로 고르고 싶어요. 나중에 변형을 더 추가해도 무작위로 선택하는 코드를 수정하지 않도록요. 이런 방법을 시도해 봤어요:…
Nim에서는 나머지를 어떻게 표현하나요? cell % 7 == 0를 쓰면 undeclared identifier: '%'가 나옵니다 Google로 검색해도 SO를 찾아봐도 답을 찾지 못했습니다.
함수 실행이 끝나면 어떤 값을 반환하게 하려면 어떻게 하나요? 예를 들어 이런 것이 있습니다: ROUTINE N ? N ⍴ 12 //이것은 1부터 12까지의 난수 N개를 만듭니다 (N은 함수의 인수입니다). 함수의 결과를 돌…