Skip to content

Commit

Permalink
fixing more show methods
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Aug 24, 2012
1 parent 44f31da commit 1aa1d88
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 28 deletions.
28 changes: 14 additions & 14 deletions examples/graph.jl
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ type ILVertex <: Vertex
end

#print(v::ILVertex) = print("Vertex $(v.name): $(v.value)")
show(v::ILVertex) = (v.value == 0 ?
print("Vertex $(v.name)") :
print("Vertex $(v.name): $(v.value)"))
show(io,v::ILVertex) = (v.value == 0 ?
print(io, "Vertex $(v.name)") :
print(io, "Vertex $(v.name): $(v.value)"))

type ILEdge <: Edge
v1::ILVertex
Expand All @@ -112,9 +112,9 @@ type ILEdge <: Edge
end

#print(e::ILEdge) = print("Edge: $(e.v1), $(e.v2): $(e.value)")
show(e::ILEdge) = (e.value == 0 ?
print("Edge $(e.v1.name),$(e.v2.name)") :
print("Edge $(e.v1.name),$(e.v2.name): $(e.value)"))
show(io, e::ILEdge) = (e.value == 0 ?
print(io,"Edge $(e.v1.name),$(e.v2.name)") :
print(io,"Edge $(e.v1.name),$(e.v2.name): $(e.value)"))

ILEdge(v1, v2) = ILEdge(v1, v2, 0)

Expand All @@ -134,7 +134,7 @@ end


#print(G::ILGraph) = (for edge = G.edges; println(edge); end)
show(G::ILGraph) = (for edge = G.edges; println(edge); end)
show(io, G::ILGraph) = (for edge = G.edges; println(io, edge); end)

function ILGraph(edges)
this = ILGraph()
Expand Down Expand Up @@ -368,12 +368,12 @@ end
sides(side::Bool) = (side ? "A" : "B")

#print(v::BVertex) = print("Vertex $(v.name): $(v.value)")
function show(v::BVertex)
function show(io, v::BVertex)
side = sides(v.side)
if v.value == 0
print("Vertex $side/$(v.name)")
print(io, "Vertex $side/$(v.name)")
else
print("Vertex $side/$(v.name): $(v.value)")
print(io, "Vertex $side/$(v.name): $(v.value)")
end
end

Expand All @@ -384,9 +384,9 @@ type BEdge <: Edge
end

#print(e::BEdge) = print("Edge: $(e.v1), $(e.v2): $(e.value)")
show(e::BEdge) = (e.value == 0 ?
print("Edge $(e.v1.name),$(e.v2.name)") :
print("Edge $(e.v1.name),$(e.v2.name): $(e.value)"))
show(io, e::BEdge) = (e.value == 0 ?
print(io,"Edge $(e.v1.name),$(e.v2.name)") :
print(io,"Edge $(e.v1.name),$(e.v2.name): $(e.value)"))

BEdge(v1, v2) = BEdge(v1, v2, 0)

Expand All @@ -404,7 +404,7 @@ type BGraph <: Graph
end

#print(G::BGraph) = (for edge = G.edges; println(edge); end)
show(G::BGraph) = (for edge = G.edges; println(edge); end)
show(io, G::BGraph) = (for edge = G.edges; println(io,edge); end)

function BGraph(edges)
this = BGraph()
Expand Down
28 changes: 14 additions & 14 deletions examples/quaternion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,35 +21,35 @@ promote_rule{S}(::Type{Bool}, ::Type{Quaternion{S}}) = Quaternion{S}
promote_rule{T<:Real,S}(::Type{T}, ::Type{Quaternion{S}}) =
Quaternion{promote_type(T,S)}

function show(z::Quaternion)
show(z.q0)
function show(io, z::Quaternion)
show(io, z.q0)
i = z.q1
if sign(i) == -1
i = -i
print(" - ")
print(io, " - ")
else
print(" + ")
print(io, " + ")
end
show(i)
print("i")
show(io, i)
print(io, "i")
j = z.q2
if sign(j) == -1
j = -j
print(" - ")
print(io, " - ")
else
print(" + ")
print(io, " + ")
end
show(j)
print("j")
show(io, j)
print(io, "j")
k = z.q3
if sign(k) == -1
k = -k
print(" - ")
print(io, " - ")
else
print(" + ")
print(io, " + ")
end
show(k)
print("k")
show(io, k)
print(io, "k")
end

real(z::Quaternion) = z.q0
Expand Down

2 comments on commit 1aa1d88

@StefanKarpinski
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't these all generally be dispatched as io::IO?

@JeffBezanson
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eh, there were no ambiguities, so I didn't notice.

Please sign in to comment.