Skip to content

Instantly share code, notes, and snippets.

@tlnagy
Last active March 15, 2016 20:45
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 tlnagy/547f0ce5ff17c1670c41 to your computer and use it in GitHub Desktop.
Save tlnagy/547f0ce5ff17c1670c41 to your computer and use it in GitHub Desktop.
Example of default constructor in julia
# type definition
type NewType
b::AbstractMatrix
end
# default constructor
# initializes a new `NewType` with a random
# 5x5 matrix stored in b
NewType() = NewType(rand(5,5))
# usage
a = NewType()
println(a.b)
# output
# [0.18065947511024127 0.20672844611543173 0.8357427772816242 0.9475149318291227 0.2018026067553489
# 0.8486569720888695 0.5064739736712023 0.5118761118648694 0.9675972326371036 0.8056193686274278
# 0.4419595685228699 0.15106901323411215 0.2745389784115493 0.08999732292468865 0.39214040190074995
# 0.39065841182140093 0.5801836228433865 0.40735736581689275 0.6961360748481833 0.22798422251415906
# 0.3911601909786271 0.8565741217057348 0.2522996563602111 0.9038925137721074 0.3706475949467489]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment