diff --git a/src/list.jl b/src/list.jl index 9189b0d9..05f23879 100644 --- a/src/list.jl +++ b/src/list.jl @@ -20,7 +20,20 @@ head(x::Cons) = x.head tail(x::Cons) = x.tail Base.:(==)(x::Nil, y::Nil) = true -Base.:(==)(x::Cons, y::Cons) = (x.head == y.head) && (x.tail == y.tail) +function Base.:(==)(x::LinkedList, y::LinkedList) + # can be changed to the more elegant + # Base.:(==)(x::Cons, y::Cons) = (x.head == y.head) && (x.tail == y.tail) + # once julia supports tail call recursions + while x isa Cons && y isa Cons + x.head == y.head || return false + x = x.tail + y = y.tail + end + if x isa Cons || y isa Cons + return false + end + return true +end function Base.show(io::IO, l::LinkedList{T}) where T if isa(l,Nil)