Make @with_kw structure display with detail all its parameters

K5Julien
Mon, 05 Feb 2024 13:22:05 +0000
General Usage

Suppose that I use Parameters.jl and the following @with_kw structure:

using Parameters
using Dates
@with_kw struct Params @deftype Int
    #PARAMETERS
    foo = 5
    bar::Dict{String,Int}  = Dict("a"=>0,"b"=>1)
    time_limit::Period = Minute(30)
end

When creating an instance of this struct:

pars = Params()

When printing print(pars), I get the following:

Params
foo: Int64 5
bar: Dict{String, Int64}
time_limit: Minute

Which is fine for foo but not for bar and time_limit.

I would prefer (and also expect) the following that I hand typed:

Params
foo: Int64 5
bar: Dict{String, Int64} Dict{String, Int64} with 2 entries:
 "b" => 1
 "a" => 0
time_limit: Minute 30 minutes

Is that easily achievable? Why is the default printing method for a @with_kw struct does not display with details every types of variables?

5 posts - 4 participants