Videos from JuliaCon are now available online
2018
Previous editions: 2017 | 2016 | 2015 | 2014
Mauro Werder



Parameters.jl: keyword constructors and default values for types

Parameters.jl is a small package providing macros which add keyword constructors to types including the possibility to set default values for each field. This allows to effectively construct with types which have a large number of fields, as often encountered –for instance– to hold configurations of programs. Additionally, it provides macros to unpack (and pack) the values within a type, thus allowing to access them easily inside functions (or other scopes). using Parameters @with_kw struct MyT a::Int = 1 # … m = 1:3 # … z::String = "zzz" end myt = MyT(z="j") # MyT(1, 1:3, "j") function f(myt::MyT, x) @unpack a, m = myt m + a + x end f(myt, 1) # 3:5 Keyword constructors and default field values are so useful that they are scheduled to hit Julia during a 1.x release (#10146). But don’t wait until then, unleash their power now!

Speaker's bio