gpt4 book ai didi

julia - `new(...)` 在 Julia 中做了什么?

转载 作者:行者123 更新时间:2023-12-04 19:01:10 25 4
gpt4 key购买 nike

new()的作用是什么在 Julia ?这个问题是否足够具体?

我正在查看模块 Mocha在哪里 new(...)很常用,但我没有看到 new() 的任何定义,仅使用它,我也没有在 Julia 文档中找到对它的引用。

我认为它可能会在 Mocha 使用的模块中定义。 ,但我想我可以通过 Mocha.new 了解 new()来自 REPL,但返回 ERROR: UndefVarError: new not defined .

对于我的生活,我无法弄清楚 new(...)是在做。如果这听起来不像 Julia 的共同点,我能做些什么来尝试追踪它的定义位置?

最佳答案

来自 http://docs.julialang.org/en/release-0.4/manual/constructors/

Inner Constructor Methods

While outer constructor methods succeed in addressing the problem of providing additional convenience methods for constructing objects, they fail to address the other two use cases mentioned in the introduction of this chapter: enforcing invariants, and allowing construction of self-referential objects. For these problems, one needs inner constructor methods. An inner constructor method is much like an outer constructor method, with two differences:

  1. It is declared inside the block of a type declaration, rather than outside of it like normal methods.
  2. It has access to a special locally existent function called new that creates objects of the block’s type.

关于julia - `new(...)` 在 Julia 中做了什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37381277/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com