I think the partially modified copy of an immutable problem has been worked on 
a bit by Keno in the past.

 — John

On Nov 24, 2014, at 3:34 PM, Eric Davies <[email protected]> wrote:

> On Friday, 21 November 2014 09:44:27 UTC-6, Steven G. Johnson wrote:
> 
> On Thursday, November 20, 2014 5:37:22 PM UTC-5, Eric Davies wrote:
> (For context, I'm working on this issue: 
> https://github.com/JuliaOpt/ECOS.jl/issues/12 and dealing with these structs: 
> https://github.com/JuliaOpt/ECOS.jl/blob/master/src/types.jl#L124-L216 )
> 
> I have a C struct used in a 3rd-party C library mirrored as an immutable in 
> Julia. A pointer to the C struct is returned in another C struct, and I get 
> the immutable using pointer_to_array(...)[1]. I want to be able to modify 
> fields of the struct in-place, but immutables disallow this. How do I go 
> about this? 
> 
> Why not just use pointer_to_array(...)[1] = ...new immutable..., or 
> unsafe_store!(pointer-to-immutable, new immutable) to store a new struct 
> (build from the old struct + modifications) in the old location?
> 
> I did not know you could do those things, thanks. In general I feel that set 
> of functions is not well-explained in the documentation.
> 
> I wish there was a way to programmatically create an immutable from another 
> immutable and modified field names/values. I think my solution right now is 
> iterate over all the fields in order and check if they're to be modified, 
> store the resulting modified+unchanged values into a list and splat the list 
> in the constructor. Seems like there could be a better way to do it.  

Reply via email to