Aha, I think that's the closest thing to what I was looking for. that allows me initialize the different components in any order, which is what I was looking for. Thanks :)
On Friday, September 4, 2015 at 7:20:40 PM UTC+2, Sisyphuss wrote: > > You mindset is quite Java. > > If you want to reverse the order, you can do > ``` > type Point > x::Float64 > y::Float64 > Point(x,y) = new(y,x) > end > > Point(1.0, 3.0) > ``` > By doing this, you overwrite the inner default constructor. > > If you want more flexible object, you may want to define outer > constructors. > > By the way, you can always give an arbitrary initial value to Point, and > then do what you like. I think this is the most economical way for you. > > > > > > On Friday, September 4, 2015 at 6:49:47 PM UTC+2, Ferran Mazzanti wrote: >> >> Dear all, >> I was wonder if it is possible to do in Julia what I can do in other >> languages, such as define a user type, as for instance >> >> type Point >> x::Float64 >> y::Float64 >> end >> >> and then define a new varible of that type, but do not initialize it, as >> in >> >> z::Point >> >> which obviously doesn't work (unless in the local scope of a function, >> with z being passed as an argument to the function). >> >> I ask because I am used to use pointers (in other languages), declare the >> pointer, allocate room for the object, and then >> use an instance of the object and initialize the different components in >> the order I like. I mean to say something of the form, inventing my >> own instructions :) >> >> ype Point >> x::Float64 >> y::Float64 >> end >> z::Point >> allocate(z) >> z.y = 2.0 >> z.x = 3.1 >> >> In Julia the only way I know to initialize the object is to pass values >> to it in exactly the same order the different fields appear in the >> type deffinition. Look as I have changed this order in my invented piexe >> of code... >> >> Any hint appreciated. >> >> Thanks. >> >
