Andrei Alexandrescu, el 7 de octubre a las 03:20 me escribiste: > On 10/7/10 1:43 CDT, Russel Winder wrote: > >On Wed, 2010-10-06 at 23:08 -0700, Walter Bright wrote: > >>If expr represents a tuple, we (Andrei and I) were thinking about the > >>syntax: > >> > >> auto (a, b, c, d) = expr; > >> > >>being equivalent to: > >> > >> auto t = expr; auto a = t[0]; auto b = t[1]; auto c = t[2 .. $];
I guess d being missing is a typo, right? > >>You can also do this with arrays, such that: > >> > >> float[3] xyz; > >> auto (x, y, z) = xyz; > >> > >>The Lithpers among you will notice that this essentially provides a handy > >>car,cdr shortcut for tuples and arrays: > >> > >> auto (car, cdr) = expr; > > > > > >Python may be the best base to compare things to as tuple assignment has > >been in there for years. > > > >Pythons choice is not a car/cdr approach but an exact match approach. > > So then we'd have the proposed notation not work with dynamic arrays > - only with static arrays and tuples. Unless you add a dynamic "bound" check as when accessing a dynamic array item, something like: auto t = expr; assert (t.lenght == 4); auto a = t[0]; auto b = t[1]; auto c = t[2]; auto d = t[3]; I like the idea of having exact match approach and the explicit syntax for getting the rest as Brad said. But in all the years I used Python, I never needed that syntax, maybe because most of the times when I use the tuple expansion I know the size or I want to truncate, or I use something to generate the data, like split(), that takes an extra parameter to do that: l = [1, 2, 3] a, b, c = l # known lenght a, b = l[:2] # truncation (like l[0..2] in D) a, b = '1,2,3'.split(',', 1) # get the rest in b (but it will be a string) car, cdr = l[0], l[1:] # just a little more verbose -- Leandro Lucarella (AKA luca) http://llucax.com.ar/ ---------------------------------------------------------------------- GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145 104C 949E BFB6 5F5A 8D05) ---------------------------------------------------------------------- careful to all animals (never washing spiders down the plughole), keep in contact with old friends (enjoy a drink now and then), will frequently check credit at (moral) bank (hole in the wall),