Skip to content

Commit 6d8f119

Browse files
committed
Prettier Static Printing
1 parent 6d18933 commit 6d8f119

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/ranges.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,3 +464,15 @@ end
464464
lst = _try_static(static_last(x), static_last(y))
465465
return Base.Slice(OptionallyStaticUnitRange(fst, lst))
466466
end
467+
468+
function Base.show(io::IO, r::OptionallyStaticRange)
469+
print(io, first(r))
470+
if known_step(r) === 1
471+
print(io, ":")
472+
else
473+
print(io, ":")
474+
print(io, step(r))
475+
print(io, ":")
476+
end
477+
print(io, last(r))
478+
end

src/static.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11

22
"""
3+
StaticInt(N::Int) -> StaticInt{N}()
4+
35
A statically sized `Int`.
46
Use `StaticInt(N)` instead of `Val(N)` when you want it to behave like a number.
57
"""
68
struct StaticInt{N} <: Integer
79
StaticInt{N}() where {N} = new{N::Int}()
810
end
911

12+
Base.show(io::IO, ::StaticInt{N}) where {N} = print(io, "Static($N)")
13+
1014
const Zero = StaticInt{0}
1115
const One = StaticInt{1}
1216

0 commit comments

Comments
 (0)