所以这是我的代码
abstract AbstractNode
type Edge
source::AbstractNode
target::AbstractNode
Edge(source::AbstractNode, target::AbstractNode) = new(source, target)
end
type Node <: AbstractNode
edgeList::Vector{Edge}
Node() = new([])
end
a = Node()
b = Node()
edge = Edge(a,b)
push!(a.edgeList, edge)
如果运行此代码,则a
存储edge
本身存储的内容a
。在Python中,这不会引起问题,但是使用Julia时,我进入了一个递归循环,并得到了StackOverFlowError()(大喊大叫!:-))。我该如何解决?
此问题已在Julia 0.3中修复,即我得到了
julia> push!(a.edgeList, edge)
1-element Array{Edge,1}:
Edge(Node([Edge(#= circular reference =#)]),Node([]))
这是修复此“错误”的拉取请求(仅在输出意义上是错误-数据结构本身当然很好)。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句