Skip to content

Instantly share code, notes, and snippets.

@bicycle1885
Last active September 13, 2015 04:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bicycle1885/c75fcd011f822fb94818 to your computer and use it in GitHub Desktop.
Save bicycle1885/c75fcd011f822fb94818 to your computer and use it in GitHub Desktop.
New v0.4 features.
type Foo
x
Foo(x::Int) = new(x)
end
Base.convert(::Type{Foo}, x::Integer) = Foo(convert(Int, x))
@show Foo(1) # ok both on v0.3 and v0.4
@show Foo(0x01) # ok on v0.4, but not on v0.3
"""
Point type.
This is a type to represent a point in 3D Cartesian coordinate system.
Fields:
* `x`: coordinate of X axis.
* `y`: coordinate of Y axis.
* `z`: coordinate of Z axis.
"""
type Point
x::Float64
y::Float64
z::Float64
end
"Enclidean distance from the origin."
function distance(p::Point)
sqrt(p.x^2 + p.y^2 + p.z^2)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment