Parameters

Types with default field values, keyword constructors and (un-)pack macros


Keywords
julia
License
Other

Documentation

Parameters

Documentation Status

Build Status Build Status

Parameters Parameters Parameters

This is a package I use to handle numerical-model parameters, thus the name. However, it should be useful otherwise too. Its main feature is the macro @with_kw which decorates a type definition and creates:

  • a keyword constructor for the type
  • allows setting default values for the fields inside the type definition
  • allows assertions on field values inside the type definition
  • a constructor which allows creating a type-instance taking its defaults from another type instance
  • packing and unpacking macros for the type: @unpack_* where * is the type name.
  • generic packing and unpacking macros @pack, @unpack (work with any types).

The keyword-constructor and default-values functionality will probably make it into Julia (# 10146, #533 and #6122) although probably not with all the features present in this package. I suspect that this package should stay usable & useful even after this change lands in Julia. Note that keyword functions are currently slow in Julia, so these constructors should not be used in hot inner loops. However, the normal positional constructor is also provided and could be used in performance critical code.

NEWS.md keeps tabs on updates.

Documentation

Documentation is here.

TODO

  • do copy of fields on (re-)construct?
  • think about mutables