<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="julia&gt; last(CartesianIndex(1, 1, 2))
ERROR: MethodError: no method matching lastindex(::CartesianIndex{3})
Closest candidates are:
  lastindex(::Markdown.MD) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.4/Markdown/src/parse/parse.jl:26
  lastindex(::Base64.Buffer) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.4/Base64/src/buffer.jl:19
  lastindex(::Cmd) at process.jl:639
  ...
Stacktrace:
 [1] last(::CartesianIndex{3}) at ./abstractarray.jl:362
 [2] top-level scope at REPL[30]:1

julia&gt; first(CartesianIndex(1, 1, 2))
ERROR: iteration is deliberately unsupported for CartesianIndex. Use `I` rather than `I...`, or use `Tuple(I)...`
Stacktrace:
 [1] error(::String) at ./error.jl:33
 [2] iterate(::CartesianIndex{3}) at ./multidimensional.jl:164
 [3] first(::CartesianIndex{3}) at ./abstractarray.jl:341
 [4] top-level scope at REPL[35]:1"><pre class="notranslate"><code class="notranslate">julia&gt; last(CartesianIndex(1, 1, 2))
ERROR: MethodError: no method matching lastindex(::CartesianIndex{3})
Closest candidates are:
  lastindex(::Markdown.MD) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.4/Markdown/src/parse/parse.jl:26
  lastindex(::Base64.Buffer) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.4/Base64/src/buffer.jl:19
  lastindex(::Cmd) at process.jl:639
  ...
Stacktrace:
 [1] last(::CartesianIndex{3}) at ./abstractarray.jl:362
 [2] top-level scope at REPL[30]:1

julia&gt; first(CartesianIndex(1, 1, 2))
ERROR: iteration is deliberately unsupported for CartesianIndex. Use `I` rather than `I...`, or use `Tuple(I)...`
Stacktrace:
 [1] error(::String) at ./error.jl:33
 [2] iterate(::CartesianIndex{3}) at ./multidimensional.jl:164
 [3] first(::CartesianIndex{3}) at ./abstractarray.jl:341
 [4] top-level scope at REPL[35]:1
</code></pre></div>
<p dir="auto">Is there some reason why</p>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="lastindex(::CartesianIndex{N}) where {N} = N
first(i::CartesianIndex) = i[1]"><pre class="notranslate"><span class="pl-en">lastindex</span>(<span class="pl-k">::</span><span class="pl-c1">CartesianIndex{N}</span>) <span class="pl-k">where</span> {N} <span class="pl-k">=</span> N
<span class="pl-en">first</span>(i<span class="pl-k">::</span><span class="pl-c1">CartesianIndex</span>) <span class="pl-k">=</span> i[<span class="pl-c1">1</span>]</pre></div>
<p dir="auto">are not defined?</p>
<p dir="auto">I have this type:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="## Amino Acid encoded as Integer, like in MATLAB's aminolookup (1:25) and Amino Acid Index Database (1:20)
immutable AminoAcidInteger &lt;: AbstractAminoAcid
    byte::Uint8
end"><pre class="notranslate"><code class="notranslate">## Amino Acid encoded as Integer, like in MATLAB's aminolookup (1:25) and Amino Acid Index Database (1:20)
immutable AminoAcidInteger &lt;: AbstractAminoAcid
    byte::Uint8
end
</code></pre></div>
<p dir="auto">With this <code class="notranslate">show</code> and <code class="notranslate">write</code> definitions:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="## Printing and Writing BioUnit as Char
write(io::IO,x::BioUnit) = write(io,uint8(x))
show(io::IO,x::BioUnit) = (write(io,x); nothing)"><pre class="notranslate"><code class="notranslate">## Printing and Writing BioUnit as Char
write(io::IO,x::BioUnit) = write(io,uint8(x))
show(io::IO,x::BioUnit) = (write(io,x); nothing)
</code></pre></div>
<p dir="auto">When I write it to a file, I get garbage instead of the values showed on REPL:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="julia&gt; seq = [ convert(NucleotideApe,i) for i in b&quot;ACTG&quot; ]
4-element NucleotideApe Array:
 A
 C
 T
 G

julia&gt; fh = open(&quot;example.txt&quot;,&quot;w&quot;)
IOStream(&lt;file example.txt&gt;)

julia&gt; write(fh,seq)
4

julia&gt; close(fh)

julia&gt; run(`cat example.txt`)
�(�H

julia&gt; fh = open(&quot;example.txt&quot;,&quot;w&quot;)
IOStream(&lt;file example.txt&gt;)

julia&gt; write(fh,seq[1])
1

julia&gt; close(fh)

julia&gt; run(`cat example.txt`)
A

julia&gt; @which write(fh,seq)
write{T}(s::IOStream,a::Array{T,N}) at io.jl:311

julia&gt; @which write(fh,seq[1])
write{T&lt;:BioUnit}(io::IO,x::T&lt;:BioUnit) at /home/dzea/NewSeqII/Compound.jl:178"><pre class="notranslate"><code class="notranslate">julia&gt; seq = [ convert(NucleotideApe,i) for i in b"ACTG" ]
4-element NucleotideApe Array:
 A
 C
 T
 G

julia&gt; fh = open("example.txt","w")
IOStream(&lt;file example.txt&gt;)

julia&gt; write(fh,seq)
4

julia&gt; close(fh)

julia&gt; run(`cat example.txt`)
�(�H

julia&gt; fh = open("example.txt","w")
IOStream(&lt;file example.txt&gt;)

julia&gt; write(fh,seq[1])
1

julia&gt; close(fh)

julia&gt; run(`cat example.txt`)
A

julia&gt; @which write(fh,seq)
write{T}(s::IOStream,a::Array{T,N}) at io.jl:311

julia&gt; @which write(fh,seq[1])
write{T&lt;:BioUnit}(io::IO,x::T&lt;:BioUnit) at /home/dzea/NewSeqII/Compound.jl:178
</code></pre></div>
<p dir="auto"><code class="notranslate">write</code> is defined. <code class="notranslate">show</code> is defined using <code class="notranslate">write</code> and works fine. On REPL and for single objects are fine... Why printing a vector gives garbage?</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="julia&gt; isbits(Nucleotide)
true"><pre class="notranslate"><code class="notranslate">julia&gt; isbits(Nucleotide)
true
</code></pre></div>