[plugin] dirstate experiments

John Arbash Meinel john at arbash-meinel.com
Fri Jun 16 16:07:50 BST 2006


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Jamie Wilkinson wrote:
> This one time, at band camp, Andrew Bennetts wrote:
>> On Fri, Jun 16, 2006 at 02:49:30AM +1000, Robert Collins wrote:
>> [...]
>>> just randomly, you might try:
>>>
>>>  x, y, z = (x1, x2), (y1, y2, y3), (z1, z2, z3) = list[1:9]
>>>
>>> No idea if it will play...
>> No luck here.  Python sees an attempt to unpack a sequence of eight items into a
>> sequence of three items, so it throws a ValueError.
>>
>> The closest you could do to what you wrote would be:
>>
>>    x1, x2, y1, y2, y3, z1, z2, z3 = list[1:9]
>>    x, y, z = (x1, x2), (y1, y2, y3), (z1, z2, z3)
> 
> How about
> 
>  x, y, z = tuple(list[1:3]), tuple(list[3:6]), tuple(list[6:9])
> 
> ?

I'm happy to discuss this, but it is really off track. The specific
problem in question is splitting a list into a tuple/list of
tuples/lists inside of a list comprehension, and I think it is
impossible because of side-effects.

Specifically I want to change a list of 1:100, into chunks of
[[1:5, 6:10], [11:15,16:20], ...]

I can do it with a plain list and just using:

out = [(foo[cur:cur+5], foo[cur+5:cur+10]) for cur in xrange(100)]

That I've worked out. The problem is if I need to process each entry in
the list, and then split up those chunks. Specifically this loop:

out = []
for entry in foo:
  chunks = entry.split('\0')
  out.append((chunks[0:5], chunks[6:10]))

The problem is that entry.split() has a side-effect, and you need a
named variable to operate on.

But my latest dirstate avoids the second problem, and just builds up the
big list like the first example.

John
=:->

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFEkslGJdeBCYSNAAMRAukcAJ9Kn4F8ayreomBxOV7auaqu/R6M8ACfUJ51
qiVaXrbanwFlvXcKPDwGDxg=
=ZAma
-----END PGP SIGNATURE-----




More information about the bazaar mailing list