Re: [julia-users] Re: Composite type with dependent fields (using Base.setindex!)

2014-07-10 Thread Mauro
Tim beat me to it... This can be implemented in current Julia. The consent among most adults is that type fields are private and consequently one uses functions to 'query' an instance of the type. In your case is should look something like: type DiscreteRv{T <: Real} q::Vector{T} Q::Vec

Re: [julia-users] Re: Composite type with dependent fields (using Base.setindex!)

2014-07-10 Thread Spencer Lyon
Thanks for the interesting suggestion. I will have to experiment with that. FWIW, this is the python code I am trying to “replicate”: class DiscreteRV(object): """ Generates an array of draws from a discrete random variable with vector of probabilities given by q. """ d

Re: [julia-users] Re: Composite type with dependent fields (using Base.setindex!)

2014-07-10 Thread Tim Holy
If you're in the consenting-adults camp, overloading setindex! would be fine. Modulo bounds, error-checking, etc, it's as simple as function setindex!(rv::DiscreteRv, val, indx) rv.q[indx] = val for j = indx:length(rv.Q) rv.Q[j] = rv.Q[j-1]+rv.q[j] end rv end If you want

[julia-users] Re: Composite type with dependent fields (using Base.setindex!)

2014-07-10 Thread Spencer Lyon
So I read through issue 1974 . It seems like what I am trying to do is not possible before that gets implemented. Is that correct? On Thursday, July 10, 2014 1:15:14 AM UTC-4, Spencer Lyon wrote: I have a very simple composite type: > > type Dis