These sorts of VarNames are non-sense, and I think the constructor should call them out and error:
julia> @varname(a.b[1:4].c)
a.b[1:4].c
What would this mean? It could mean get the elements a.b[1:4] and get the field .c for each of them. However, that's not what this does in Julia. Rather, in Julia, indexing like that tries to get the field .c of the object a.b[1:4], which is probably an Array that only has fields ref and size. I don't think that's ever the thing we want to do in a probabilistic programming language context. Hence I think VarNames should allow an IndexLens with ranges or Colons only as the last lens.
Note that this should of course still be fine: @varname(a.b[2].c)
These sorts of
VarNames are non-sense, and I think the constructor should call them out and error:What would this mean? It could mean get the elements
a.b[1:4]and get the field.cfor each of them. However, that's not what this does in Julia. Rather, in Julia, indexing like that tries to get the field.cof the objecta.b[1:4], which is probably anArraythat only has fieldsrefandsize. I don't think that's ever the thing we want to do in a probabilistic programming language context. Hence I thinkVarNames should allow anIndexLenswith ranges orColons only as the last lens.Note that this should of course still be fine:
@varname(a.b[2].c)