85
85
86
86
tupleindex2lens (indexing:: Tuple{} ) = IdentityLens ()
87
87
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
90
91
91
92
"""
92
93
getsym(vn::VarName)
@@ -143,18 +144,23 @@ end
143
144
144
145
145
146
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
148
150
149
151
# 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
152
155
153
156
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.
154
159
print (io, getsym (vn))
155
160
_print_application (io, vn. indexing)
156
161
end
157
162
163
+ # This is all just to allow to convert `Colon()` into `:`.
158
164
_print_application (io:: IO , l:: Lens ) = Setfield. print_application (io, l)
159
165
function _print_application (io:: IO , l:: ComposedLens )
160
166
_print_application (io, l. outer)
@@ -174,9 +180,13 @@ prettify_index(::Colon) = ":"
174
180
175
181
Return a `Symbol` represenation of the variable identifier `VarName`.
176
182
183
+ # Examples
177
184
```jldoctest
178
185
julia> Symbol(@varname(x[1][2:3]))
179
186
Symbol("x[1][2:3]")
187
+
188
+ julia> Symbol(@varname(x[1][:]))
189
+ Symbol("x[1][:]")
180
190
```
181
191
"""
182
192
Base. Symbol (vn:: VarName ) = Symbol (string (vn)) # simplified symbol
0 commit comments