Skip to content

Commit a397bfe

Browse files
committed
formatting and new show
1 parent 2019180 commit a397bfe

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

src/varname.jl

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,9 @@ end
8585

8686
tupleindex2lens(indexing::Tuple{}) = IdentityLens()
8787
tupleindex2lens(indexing::Tuple{<:Tuple}) = IndexLens(first(indexing))
88-
tupleindex2lens(indexing::Tuple) =
89-
IndexLens(first(indexing)) tupleindex2lens(indexing[2:end])
88+
function tupleindex2lens(indexing::Tuple)
89+
return IndexLens(first(indexing)) tupleindex2lens(indexing[2:end])
90+
end
9091

9192
"""
9293
getsym(vn::VarName)
@@ -143,18 +144,23 @@ end
143144

144145

145146
Base.hash(vn::VarName, h::UInt) = hash((getsym(vn), getindexing(vn)), h)
146-
Base.:(==)(x::VarName, y::VarName) =
147-
getsym(x) == getsym(y) && getindexing(x) == getindexing(y)
147+
function Base.:(==)(x::VarName, y::VarName)
148+
return getsym(x) == getsym(y) && getindexing(x) == getindexing(y)
149+
end
148150

149151
# Allow compositions with lenses.
150-
Setfield.compose(vn::VarName{sym,<:Lens}, lens::Lens) where {sym} =
151-
VarName{sym}(vn.indexing lens)
152+
function Base.:(vn::VarName{sym,<:Lens}, lens::Lens) where {sym}
153+
return VarName{sym}(vn.indexing lens)
154+
end
152155

153156
function Base.show(io::IO, vn::VarName{<:Any,<:Lens})
157+
# No need to check `Setfield.has_atlens_support` since
158+
# `VarName` does not allow dynamic lenses.
154159
print(io, getsym(vn))
155160
_print_application(io, vn.indexing)
156161
end
157162

163+
# This is all just to allow to convert `Colon()` into `:`.
158164
_print_application(io::IO, l::Lens) = Setfield.print_application(io, l)
159165
function _print_application(io::IO, l::ComposedLens)
160166
_print_application(io, l.outer)
@@ -174,9 +180,13 @@ prettify_index(::Colon) = ":"
174180
175181
Return a `Symbol` represenation of the variable identifier `VarName`.
176182
183+
# Examples
177184
```jldoctest
178185
julia> Symbol(@varname(x[1][2:3]))
179186
Symbol("x[1][2:3]")
187+
188+
julia> Symbol(@varname(x[1][:]))
189+
Symbol("x[1][:]")
180190
```
181191
"""
182192
Base.Symbol(vn::VarName) = Symbol(string(vn)) # simplified symbol

0 commit comments

Comments
 (0)