Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

show that only shows non-default values #12

Open
aplavin opened this issue Aug 10, 2024 · 4 comments
Open

show that only shows non-default values #12

aplavin opened this issue Aug 10, 2024 · 4 comments

Comments

@aplavin
Copy link

aplavin commented Aug 10, 2024

Would be nice to omit default values in show() of structs that have defaults:

julia> @kwdef struct S
       a = 1
       b = 2
       end

julia> @batteries S kwshow=true

julia> S()
S(a = 1, b = 2)  # could be S()

julia> S(b=10)
S(a = 1, b = 10)  # could be S(b = 10)

Especially useful for large structs, but nice even with only a couple of parameters.

@jw3126
Copy link
Owner

jw3126 commented Aug 11, 2024

Great suggestion.

@jw3126
Copy link
Owner

jw3126 commented Aug 11, 2024

Actually this seems tricky. How do we know what is a default value?

@aplavin
Copy link
Author

aplavin commented Aug 13, 2024

Hmm, yeah, unfortunately @kwdef doesn't provide a public way to access defaults. Only extracting them from the constructor signature... Or upgrading @kwdef :)

@aplavin
Copy link
Author

aplavin commented Aug 27, 2024

May be added soon: JuliaLang/julia#55599.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants