[Swift-devel] a different way to do array/structure accesses

Mihael Hategan hategan at mcs.anl.gov
Fri Jun 29 20:45:51 CDT 2007


On Sat, 2007-06-30 at 01:34 +0000, Ben Clifford wrote:
> alternatively, I guess the path argument can be constructed on the fly (as 
> it looks like it might have been intended to once):
> 
>          <vdl:getfield var="{a}">
>             <argument name="path">
>               <concat>
>                 <string>[<string>
>                 ... compiled expression code here ...
>                 <string>]</string>
>               </concat>
>            </argument>
>           </vdl:getfield>..
> 
> That's less aesthetically pleasing to me than the multiple-getfield form, 
> though.

Again, if constant nested getfields are reduced to a single path, it's
probably fine to keep dynamic things as nested getfields (it's the only
case incurring performance penalties).

e.g. p.x.z.v[i].a:
gfv(gfv(gfv(p, "x.z.v"), gfv(i)), "a"))

Also, we could probably make this nicer with vargs (which will solve the
problem anyway):
gfv(p, "x", "z", "v", gfv(i), "a")

> 
> On the gripping hand, we could say that array subscripts can only be 
> constants or variable names and disallow expressions there. That perhaps 
> reflects the status quo more accurately, although I don't like it.

Me neither. And it's counterintuitive. There will be hundreds trying to
do it anyway (assuming we will have those many users :)

> 




More information about the Swift-devel mailing list