I would like to discourage you from passing symbols as an array index but I 
guess you gonna do it anyway...


So if you really want it, here it is:
setindex!(p::Population, value, field::Symbol, index...) = p.individuals[
index...].(field) = value
getindex(p::Population, field::Symbol, index...) = p.individuals[index...].(
field)

Usage
population[:infected, 1]
population[:infected, 1] = false




On Saturday, June 4, 2016 at 2:19:02 PM UTC+2, Christopher Fisher wrote:
>
> I was wondering if someone would be willing to help me with creating 
> user-defined types. I've been using Julia for about two years now but I am 
> new to the idea of creating custom types. I'm trying to create a population 
> of agents/individuals in a simple epidemiological simulation. I would like 
> the population of individuals to be structured as a  2 dimensional array 
> with rows as individuals and columns as properties. This would be somewhat 
> similar to a DataFrame, but potentially more flexible. I want to be able to 
> index an individual like so: population[1]. This woud list all of the 
> information for individual 1.  I would also like to be able to look at an 
> attribute across individuals: population.infected or population[:infected]. 
> At the same time, I would like to have to flexibility of using an array to 
> keep track of individuals: typeof(population.history[1]) is Array{Int64,1}. 
> Based on existing documentation and examples, I have only been able to 
> create individuals but cannot figure out how to create a population as 
> described above:
>
> type Person
>     infected::Int64
>     vaccinated::Int64
>     dead::Int64
>    history::Array{Int64,1}
> end
>
> Any help would be greatly appreciated. 
>

Reply via email to