Ben, much as I would like there to be a second kind of typealias, *typealiased 
-- *that let us work with the renanamings wiithout risk to the objects of 
the type originally aliased -- this is not on the radar now.  It is hard to 
peel off enough to form the CIGAR when the role of typealias is to preclude 
introducing distictiction outside of recognizing a the alias as if it were 
a nickname.



On Friday, August 14, 2015 at 7:26:07 PM UTC-4, Ben Ward wrote:
>
> 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.
>>>
>>

Reply via email to