www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Re: Tuple assignment

reply bearophile <bearophileHUGS lycos.com> writes:
Juanjo Alvarez:

 Python has the special symbol "_" which is used exactly as
 a no-op (you could call it "foo" it you wanted, but "_"
 doesn't create new memory assignments) so you can expand
 arbitrary tuples without creating new symbols:
 
 a, b, c, _ = ('tuple', 'of', 'three')

This is false both in Python2 and Python3. In Python3 there is the syntax: a, *bc = ('tuple', 'of', 'three') That's semantically similar to the proposed D syntax: auto record(a, bc...) = record('tuple', 'of', 'three') Bye, bearophile
Oct 07 2010
parent reply Juanjo Alvarez <fake fakeemail.com> writes:
On Thu, 07 Oct 2010 15:14:12 -0400, bearophile 
<bearophileHUGS lycos.com> wrote:
 This is false both in Python2 and Python3.

What is exactly false on what I said?
 a, *bc = ('tuple', 'of', 'three')

Yes, that's the syntax for assignment of the remainder, I was speaking about *ignoring* the remainder without having it assigned to the last element which was one of the proposed effects in the message before mine's.
Oct 07 2010
parent =?UTF-8?B?IkrDqXLDtG1lIE0uIEJlcmdlciI=?= <jeberger free.fr> writes:
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

Juanjo Alvarez wrote:
 On Thu, 07 Oct 2010 15:14:12 -0400, bearophile
 <bearophileHUGS lycos.com> wrote:
 This is false both in Python2 and Python3.

=20 What is exactly false on what I said?

 python

[GCC 4.4.3 20100316 (prerelease)] on linux2 Type "help", "copyright", "credits" or "license" for more information.
 a, b, c, _ =3D ('tuple', 'of', 'three')



File "<stdin>", line 1, in <module> ValueError: need more than 3 values to unpack



Jerome --=20 mailto:jeberger free.fr http://jeberger.free.fr Jabber: jeberger jabber.fr
Oct 08 2010