我正在阅读文档中有关构造函数的部分,并且多次提到了自引用对象的概念。然而,我似乎没有找到这个术语在 Julia 的上下文中指的是什么。
这些是可以引用自身(直接或间接)的对象。请参阅下面的示例:
julia> mutable struct Node
parent::Node
Node() = new()
end;
julia> root = Node()
Node(#undef)
julia> root.parent = root
Node(Node(#= circular reference @-1 =#))
julia> function Node(parent::Node)
n = Node()
n.parent=parent
n
end;
julia> child = Node(root)
Node(Node(Node(#= circular reference @-1 =#)))
Run Code Online (Sandbox Code Playgroud)
自引用对象对构造函数和变异感兴趣的原因是,自引用对象不能在没有变异的情况下构造。