There isn't any special syntax for listing some of the type's fields, but 
you might be able to pull it off with some metaprogramming.

setdiff(names(Point), [:x]) will give you the leftover fields to use as 
default. You might be able to write a macro you could insert into the 
constructor call to copy all the other fields given that list as input.

On Monday, December 8, 2014 12:15:23 PM UTC-5, Utkarsh Upadhyay wrote:
>
> I have just tried playing with Julia and I find myself often copying 
> `immutable` objects while changing just one field:
>
> function setX(pt::Point, x::Float64)
>   # Only changing the `x` field
>   return Point(x, pt.y, pt.z, pt.color, pt.collision, pt.foo, pt.bar);
> end
>
> Is there is any syntactical sugar to avoid having to write out all the 
> other fields which are not changing (e.g. pt.y, pt.z, etc.) while creating 
> a new object?
> Apart from making the function much easier to understand, this will also 
> make it much less of a hassle to change fields on the type.
>
> Thanks.
>

Reply via email to