Bare flag sugar#18
Conversation
|
Thanks for the PR! Can you pitch the advantages of this syntactic sugar? The pro I see is slightly more concise |
75d66f0 to
61032a0
Compare
|
Thanks for having a look on this PR (and merging #17).
Yes, it's nice that the calls are a bit more concise improving the signal-to-noise ratio. However, the real reason to have this is #19:
However, for large programs, the explicit That's why both Sorry for only vaguely hinting at a "future PR", but the |
61032a0 to
093cc92
Compare
|
093cc92 to
b182dc4
Compare
A bare symbol is now accepted as shorthand for \`flag=true\`:
@Batteries T kwconstructor # equivalent to kwconstructor=true
@Batteries T kwconstructor kwshow hash=false # mixable
Also unblocks the cleaner subset-mode call shape we want for an
upcoming \`@battery\` macro that derives a single hand-picked battery.
b182dc4 to
a500064
Compare
Closes jw3126#12. This is the real PR I wanted to do. All the others are basically there to enable this one. Introduces a new `@batteries` / `@battery` flag `showrepr=true` that overloads `Base.show` to print a heuristically short constructor call which round-trips through `eval`, as an alternative to the existing `kwshow`. The two are mutually exclusive (both target `Base.show`). I originally wanted to just extend `kwshow`. However, as the redundancy reduction should also be available if there is no keyword constructor and/or calls are short when using a parametric constructor, this would have lead to broken backwards-compatibility requiring a major version bump and user changes. But as both approaches have different advantages, it's probably a good thing to have both in the future. Highlights: * Probes every constructor of the type — positional, keyword, and hybrid (including the pair synthesized by `Base.@kwdef`) — and picks the shortest call whose result is `repr_eq` to the original. Trailing fields whose values match a default are omitted. * Per-field literal shortening where the constructor still accepts the substitute: `0x000000000000002a` → `42`, whole-valued floats drop the `.0` suffix, `2//1` → `2`, `2 + 0im` → `2`. * Uniform / run-length-compressed vectors render as `fill(v, n)` (or `[v for _=1:n]` for non-`isbits` elements, to avoid aliasing on re-eval); heterogeneous vectors get per-run RLE only when it actually shortens the literal. * Round-trip safety is the gating criterion throughout: every substitution is verified by reconstructing through the constructor and comparing via `repr_eq` (which accepts both `==` and `isequal` to handle `NaN`, `-0.0`, and custom equality). * Falls back to a non-executable `T(field = value, …)` rendering when no constructor recreates the object. `kwshow` keeps its existing fixed `T(f1 = v1, …)` shape and stability guarantees; `showrepr`'s output is heuristic and not pinned across minor releases. The README contrasts the two. This builds on jw3126#18 and jw3126#19 which should be merged first. Co-authored-by: Copilot <copilot@github.com>
Closes jw3126#12. This is the real PR I wanted to do. All the others are basically there to enable this one. Introduces a new `@batteries` / `@battery` flag `showrepr=true` that overloads `Base.show` to print a heuristically short constructor call which round-trips through `eval`, as an alternative to the existing `kwshow`. The two are mutually exclusive (both target `Base.show`). I originally wanted to just extend `kwshow`. However, as the redundancy reduction should also be available if there is no keyword constructor and/or calls are short when using a parametric constructor, this would have lead to broken backwards-compatibility requiring a major version bump and user changes. But as both approaches have different advantages, it's probably a good thing to have both in the future. Highlights: * Probes every constructor of the type — positional, keyword, and hybrid (including the pair synthesized by `Base.@kwdef`) — and picks the shortest call whose result is `repr_eq` to the original. Trailing fields whose values match a default are omitted. * Per-field literal shortening where the constructor still accepts the substitute: `0x000000000000002a` → `42`, whole-valued floats drop the `.0` suffix, `2//1` → `2`, `2 + 0im` → `2`. * Uniform / run-length-compressed vectors render as `fill(v, n)` (or `[v for _=1:n]` for non-`isbits` elements, to avoid aliasing on re-eval); heterogeneous vectors get per-run RLE only when it actually shortens the literal. * Round-trip safety is the gating criterion throughout: every substitution is verified by reconstructing through the constructor and comparing via `repr_eq` (which accepts both `==` and `isequal` to handle `NaN`, `-0.0`, and custom equality). * Falls back to a non-executable `T(field = value, …)` rendering when no constructor recreates the object. `kwshow` keeps its existing fixed `T(f1 = v1, …)` shape and stability guarantees; `showrepr`'s output is heuristic and not pinned across minor releases. The README contrasts the two. This builds on jw3126#18 and jw3126#19 which should be merged first. Co-authored-by: Copilot <copilot@github.com>
Closes jw3126#12. This is the real PR I wanted to do. All the others are basically there to enable this one. Introduces a new `@batteries` / `@battery` flag `showrepr=true` that overloads `Base.show` to print a heuristically short constructor call which round-trips through `eval`, as an alternative to the existing `kwshow`. The two are mutually exclusive (both target `Base.show`). I originally wanted to just extend `kwshow`. However, as the redundancy reduction should also be available if there is no keyword constructor and/or calls are short when using a parametric constructor, this would have lead to broken backwards-compatibility requiring a major version bump and user changes. But as both approaches have different advantages, it's probably a good thing to have both in the future. Highlights: * Probes every constructor of the type — positional, keyword, and hybrid (including the pair synthesized by `Base.@kwdef`) — and picks the shortest call whose result is `repr_eq` to the original. Trailing fields whose values match a default are omitted. * Per-field literal shortening where the constructor still accepts the substitute: `0x000000000000002a` → `42`, whole-valued floats drop the `.0` suffix, `2//1` → `2`, `2 + 0im` → `2`. * Uniform / run-length-compressed vectors render as `fill(v, n)` (or `[v for _=1:n]` for non-`isbits` elements, to avoid aliasing on re-eval); heterogeneous vectors get per-run RLE only when it actually shortens the literal. * Round-trip safety is the gating criterion throughout: every substitution is verified by reconstructing through the constructor and comparing via `repr_eq` (which accepts both `==` and `isequal` to handle `NaN`, `-0.0`, and custom equality). * Falls back to a non-executable `T(field = value, …)` rendering when no constructor recreates the object. `kwshow` keeps its existing fixed `T(f1 = v1, …)` shape and stability guarantees; `showrepr`'s output is heuristic and not pinned across minor releases. The README contrasts the two. This builds on jw3126#18 and jw3126#19 which should be merged first. Co-authored-by: Copilot <copilot@github.com>
Closes jw3126#12. This is the real PR I wanted to do. All the others are basically there to enable this one. Introduces a new `@batteries` / `@battery` flag `showrepr=true` that overloads `Base.show` to print a heuristically short constructor call which round-trips through `eval`, as an alternative to the existing `kwshow`. The two are mutually exclusive (both target `Base.show`). I originally wanted to just extend `kwshow`. However, as the redundancy reduction should also be available if there is no keyword constructor and/or calls are short when using a parametric constructor, this would have lead to broken backwards-compatibility requiring a major version bump and user changes. But as both approaches have different advantages, it's probably a good thing to have both in the future. Highlights: * Probes every constructor of the type — positional, keyword, and hybrid (including the pair synthesized by `Base.@kwdef`) — and picks the shortest call whose result is `repr_eq` to the original. Trailing fields whose values match a default are omitted. * Per-field literal shortening where the constructor still accepts the substitute: `0x000000000000002a` → `42`, whole-valued floats drop the `.0` suffix, `2//1` → `2`, `2 + 0im` → `2`. * Uniform / run-length-compressed vectors render as `fill(v, n)` (or `[v for _=1:n]` for non-`isbits` elements, to avoid aliasing on re-eval); heterogeneous vectors get per-run RLE only when it actually shortens the literal. * Round-trip safety is the gating criterion throughout: every substitution is verified by reconstructing through the constructor and comparing via `repr_eq` (which accepts both `==` and `isequal` to handle `NaN`, `-0.0`, and custom equality). * Falls back to a non-executable `T(field = value, …)` rendering when no constructor recreates the object. `kwshow` keeps its existing fixed `T(f1 = v1, …)` shape and stability guarantees; `showrepr`'s output is heuristic and not pinned across minor releases. The README contrasts the two. This builds on jw3126#18 and jw3126#19 which should be merged first. Co-authored-by: Copilot <copilot@github.com>
Allow using
@batteries T kwshowinstead of@batteries T kwshow=true. This is nice on its own, but also used in a later PR.This builds on #17, so its diff will be smaller after #17 is merged.