Base.Show - unable to print using custom print

question

#1

I am declaring a custom type as Vector2Dim and i want to output to be printed with just the coordinates instead of Vector2Dim(x,y).
However the same code if i execute in julia console it prints the desired output as [x,y] and if i write the code in a file
and execute, it prints the output as Vector2Dim(x,y).
Kindly let me know what changes do i need to make it to get the correct output. Below is the code and its output.

Julia Version 0.5.1
IDE: atom(juno)

Code::

import Base.show

type Vector2Dim
  x::Float64
  y::Float64
end

a = Vector2Dim(3,4)

println(a)

show(io::IO, v::Vector2Dim) = print(io, "[$(v.x),$(v.y)]")

println(a)

Output::

Vector2Dim(3.0,4.0)
Vector2Dim(3.0,4.0)

The required output is [3.0, 4.0]


#2

This is the infamous #265 Fixed on 0.6/master.


#3

if you don’t print before defining the custom show method it should work fine on 0.5

try

import Base.show

type Vector2Dim
  x::Float64
  y::Float64
end

show(io::IO, v::Vector2Dim) = print(io, "[$(v.x),$(v.y)]")

a = Vector2Dim(3,4)

println(a)

#4

Thank you very much