[Python-ideas] values in vs. values out
Jason Orendorff
jason.orendorff at gmail.com
Thu Jan 13 22:31:39 CET 2011
On Thu, Jan 13, 2011 at 3:10 PM, Masklinn <masklinn at masklinn.net> wrote:
> On 2011-01-13, at 21:11 , Jason Orendorff wrote:
>> (c) Unlike ML, you can write
>> (a, b) = [1, 2]
>> or generally
>> a, b = any_iterable
>> It is useful for unpacking to depend on the iterable protocol
>> rather than the exact type of the right-hand side. This is a
>> nicety that ML-like languages don't bother with, afaik.
> In no small part because, in ML-type languages (or more generally in
> functional languages, Erlang could hardly be called an ML-like language)
> lists (or more generally sequences) and tuples are very different beasts and
> entirely incompatible.
Well, sure, as far as tuples go. But the point I was making was more
general. Python has a notion of "iterable" which covers many types,
not just "list". The iterable protocol is used by Python's for-loops,
sorted(), str.join() and so on; it's only natural for unpacking
assignment to use it as well. As far as I know, most ML languages
don't have that notion.* So Python has a reason for this asymmetry
that those languages don't have.
-j
*Haskell, to be sure, has several typeclasses that generalize List,
but for whatever reason it is List, and not any of the
generalizations, that is baked into the language.
More information about the Python-ideas
mailing list