英文:
julia error: method too new to be called from this world context
问题
我想要执行模块(称为daughter)的函数,通过执行另一个模块(称为mother)来实现。
为了做到这一点,我在mother中编写了如下的代码:
include("User/initialization/Background.jl")
initialization.Background() #1
然而,daughter没有工作,因为出现了以下错误:
MethodError: no method matching Background()
The applicable method may be too new: running in world age 32734, while current world is 32738.
Closest candidates are:
Background() at C:\Windows\Application Data\User\initialization\Background.jl:7 (method too new to be called from this world context.)
编辑
我现在已经添加了我的代码详细信息:
module Hi
using DelimitedFiles
function Hi_Hello()
if Command[1,1]==1
include("User/initialization/Background.jl")
initialization.Background() #1
else
end
end
end
using .Hi
Hi.Hi_Hello
和
module initialization
using Plots, DelimitedFiles, BSplineKit
function Background()
writedlm("Background.txt", data_BG)
end
end
using .initialization
initialization.Background
它在VScode中执行,而且初始化模块包含在目录中:("User/initialization)。
当我在终端上输入命令时,它可以正常工作:
include("User/initialization/Background.jl")
initialization.Background() #1
但是,当我通过执行函数来执行时,出现了我在原始帖子中提到的错误。
MethodError: no method matching Background()
The applicable method may be too new: running in world age 32734, while current world is 32738.
Closest candidates are: Background() at C:\Windows\Application Data\User\initialization\Background.jl:7 (method too new to be called from this world context.)
英文:
I want to execute the function of the module (denoted daughter) by executing another module (denoted mother).
To do that, I wrote down code as follows in the mother:
include("User/initialization/Background.jl")
initialization.Background() #1
However, the daughter didn't work because of the following error:
MethodError: no method matching Background()
The applicable method may be too new: running in world age 32734, while current world is 32738.
Closest candidates are:
Background() at C:\Windows\Application Data\User\initialization\Background.jl:7 (method too new to be called from this world context.)
Edit
I now have added the details of my code:
module Hi
using DelimitedFiles
function Hi_Hello()
if Command[1,1]==1
include("User/initialization/Background.jl")
initialization.Background() #1
else
end
end
end
using .Hi
Hi.Hi_Hello
and
module initialization
using Plots, DelimitedFiles, BSplineKit
function Background()
writedlm("Background.txt", data_BG)
end
end
using .initialization
initialization.Background
It is executing using VScode and initialization(module) included in the directory:("User/initialization).
when I command on the terminal, it works.
include("User/initialization/Background.jl")
initialization.Background() #1
but when I command through executing function, it didn't with error as I mentioned original post.
MethodError: no method matching Background() The applicable method may be too new: running in world age 32734, while current world is 32738. Closest candidates are: Background() at C:\Windows\Application Data\User\initialization\Background.jl:7 (method too new to be called from this world context.)
答案1
得分: 2
代码部分不需要翻译。以下是已翻译的内容:
"While your question does not provide enough information to identify the root of the problem (most likely it is related to some macros generating your function's code), the solution is most likely to invoke the latest version of your function. So it seems this will help (BTW module names are recommended to be started with Capital Letters):
@invokelatest initialization.Background()
```"
### Edit
After you updated the question now I can see the problem.
You should put the `include` statement *before* the function `Hi_Hello()` *not inside it*.
Normally when programming in Julia you do not want functions to dynamically include, load, and recompile modules (and hence your error).
<details>
<summary>英文:</summary>
While your question does not provide enough information to identify the root of the problem (most likely it is related to some macros generating your function's code), the solution is most likely to invoke the latest version of your function. So it seems this will help (BTW module names are recommended to be started with Capital Letters):
@invokelatest initialization.Background()
### Edit
After you updated the question now I can see the problem.
You should put the `include` statement *before* the function `Hi_Hello()` *not inside it*.
Normally when programming in Julia you do not want functions to dynamically include, load and recompile modules (and hence your error).
</details>
# 答案2
**得分**: 0
[I moved the text placed here to the main question.
Dear @Manu Han - please delete it as this is not an answer]
<details>
<summary>英文:</summary>
[I moved the text placed here to the main question.
Dear @Manu Han - please delte it as this is not an answer]
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论