January 2020
Intermediate to advanced
532 pages
13h 31m
English
Given that the keyword definition pattern addresses a fairly common use case, there is already a macro provided by Julia to help define structs along with constructors accepting keyword arguments. The macro is currently not exported, but you can use it directly as follows:
Base.@kwdef struct TextStyle font_family font_size font_weight = "Normal" foreground_color = "black" background_color= "white" alignment = "center" rotation = 0end
Basically, we can just place the Base.@kwdef macro in front of the type definition. As a part of the type definition, we can also provide default values. The macro automatically defines the struct and the corresponding constructor function with keyword arguments. We can ...
Read now
Unlock full access