The double posting that occasionally happens on these lists is usually because we moderate first-time posters and people post once and assume it was eaten by the system, and while their message is awaiting moderation, they post again. I generally just approve all of the posts. This is a bit annoying, but otherwise we get a lot of recruiting spam, which is even more annoying. Perhaps I should make a few more people moderators to reduce the expected time for moderation to occur.
On Sat, May 24, 2014 at 5:46 PM, Elliot Saba <staticfl...@gmail.com> wrote: > Hey there, Remco. Double-posting is not necessary to get a response, > things tend to get answered within a day or so, often much sooner. > > To create an object type in Julia, you can take a look at the > documentation for defining composite > types<http://julia.readthedocs.org/en/latest/manual/types/#composite-types>, > your "lastname" and "firstname" member variables can be declared as part of > a Person object like so: > > *type Person* > * firstname* > * lastname* > *end* > > If you want to force firstname and lastname to be strings, you can do so > with type annotations, as shown in the composite types link above > > To define functionality, Julia does not have member functions like many > other OOP languages. Instead, everything is done through multiple > dispatch, essentially you would define a method called "fullname" that > takes in a variable of type Person: > > *fullname(p::Person) = string(p.firstname, " ", p.lastname)* > > I suggest you read through the > methods<http://julia.readthedocs.org/en/latest/manual/methods/> section > of the manual for more on this. Note that since you're used to Ruby, you > might find it more convenient to use string interpolation instead of the > string constructor, both are equivalent, although using the string > constructor directly is more performant: > > *fullname(p::Person) = "$(p.firstname) $(p.lastname)"* > > Finally, to construct a person object, each type defined in Julia is given > a default constructor, so you can use that and initialize all fields > immediately: > > *p = Person("john", "smith")* > > If you want to define your own constructors, I suggest you read the > constructors > section <http://julia.readthedocs.org/en/latest/manual/constructors/> of > the manual. > -E > > > On Sat, May 24, 2014 at 11:10 AM, Remco <remc...@gmail.com> wrote: > >> Hi, I am new to julia and i am not sure how to do this in julia: >> >> >> class Person >> attr_accessor :lastname, :firstname >> >> def fullname >> "#{firstname} #{lastname}" >> end >> end >> >> jan = Person.new >> jan.firstname = "Jan" >> jan.lastname = "Janssen" >> >> puts jan.fullname >> >> >> Regards, Remco >> > >