@@ -123,12 +123,17 @@ function parse_obj_lenses(ex)
123123 lens = :($ IndexLens ($ index))
124124 end
125125 elseif @capture (ex, front_. property_)
126- property isa Union{Symbol,String} || throw (ArgumentError (
127- string (" Error while parsing :($ex ). Second argument to `getproperty` can only be" ,
128- " a `Symbol` or `String` literal, received `$property ` instead." )
129- ))
130126 obj, frontlens = parse_obj_lenses (front)
131- lens = :($ PropertyLens {$(QuoteNode(property))} ())
127+ if property isa Union{Symbol,String}
128+ lens = :($ PropertyLens {$(QuoteNode(property))} ())
129+ elseif is_interpolation (property)
130+ lens = :($ PropertyLens {$(esc(property.args[1]))} ())
131+ else
132+ throw (ArgumentError (
133+ string (" Error while parsing :($ex ). Second argument to `getproperty` can only be" ,
134+ " a `Symbol` or `String` literal, received `$property ` instead." )
135+ ))
136+ end
132137 elseif @capture (ex, f_ (front_))
133138 obj, frontlens = parse_obj_lenses (front)
134139 lens = :($ FunctionLens ($ (esc (f))))
@@ -231,6 +236,11 @@ julia> t = ("one", "two")
231236
232237julia> set(t, (@lens _[1]), "1")
233238("1", "two")
239+
240+ julia> # Indices are always evaluated in external scope; for properties, you can use interpolation:
241+ n, i = :a, 10
242+ @lens(_.\$ n[i, i+1])
243+ (@lens _.a[10, 11])
234244```
235245
236246"""
0 commit comments