Would that work? The variable to be printed isn't fed in as the second option?
On Wednesday, August 12, 2015 at 1:34:16 AM UTC+1, colint...@gmail.com wrote: > > Does the following work? > > function Base.show(io::IO, ::Type{CIGARString}) > #your code here > end > > > > On Tuesday, 11 August 2015 03:07:15 UTC+10, Ben Ward wrote: >> >> Hi, I have implemented a basic immutable type with a type alias for a >> vector of said type: >> >> immutable CIGAR >> OP::Operation >> Size::Int >> end >> >> >> function CIGAR(op::Char, size::Int) >> return CIGAR(Operation(op), size) >> end >> >> >> function convert(::Type{String}, cigar::CIGAR) >> return "$(cigar.Size)$(Char(cigar.OP))" >> end >> >> >> function show(io::IO, cigar::CIGAR) >> write(io, convert(String, cigar)) >> end >> >> >> typealias CIGARString Vector{CIGAR} >> >> >> function convert(::Type{CIGARString}, str::String) >> matches = matchall(r"(\d+)(\w)", str) >> cigarString = Vector{CIGAR}(length(matches)) >> @inbounds for i in 1:length(matches) >> m = matches[i] >> cigarString[i] = CIGAR(m[end], parse(Int, m[1:end-1])) >> end >> return cigarString >> end >> >> >> macro cigar_str(str) >> return CIGARString(str) >> end >> >> I also want to define a show method for the alias CIGARString, so as it >> is converted to a string that can be used with a show method: >> >> function convert(::Type{String}, cigarString::CIGARString) >> outString = "" >> for cigar in cigarString >> outString *= String(cigar) >> end >> return outString >> end >> >> >> function show(io::IO, cigarstr::CIGARString) >> write(io, convert(String, cigarstr)) >> end >> >> However the output a see on the REPL is: >> >> *3-element Array{Bio.Align.CIGAR,1}:* >> >> * 5M* >> >> * 5N* >> >> * 5M* >> >> So, rather than the show method for CIGARString being called, the show >> method for CIGAR is being called repeatedly for every element in the >> CIGARString vector. How do I get Julia to use the show method I want for >> CIGARString? >> >> Thanks. >> >