Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Status of default initialisation of struct fields?

Under Julia v0.6, the simple code:

julia> struct A
             x::Int = 1
       end   

generates this error:

ERROR: syntax: "x::Int=1" inside type definition is reserved

This is quite an elusive message: reserved for what?

-> Do I have to understand that this kind of definition is going to be allowed in future Julia revisions?

like image 846
Picaud Vincent Avatar asked Mar 07 '23 01:03

Picaud Vincent


1 Answers

This is available via Parameters.jl.

julia> using Parameters

julia> @with_kw struct A
           a::Int = 6
           b::Float64 = -1.1
           c::UInt8
       end

julia> A(c=4)
A
  a: 6
  b: -1.1
  c: 4
like image 180
Chris Rackauckas Avatar answered Mar 15 '23 13:03

Chris Rackauckas