From Newsgroup: comp.lang.python
Jon Ribbens <
jon+usenet@unequivocal.eu> writes:
My biggest complaint about := is the arbitrary and mysterious
restrictions on what you can use on the left hand side. You can't
even say "a.b := c". The PEP that introduced ":=" barely even
mentions these restrictions, let alone discusses or explains them.
Yeah that's pretty annoying. Haskell doesn't have destructive
assignments at all, but you can put the equivalent of match/case inside expressions. So, something like:
fromList [(a, read b) | (a:b:_) <- words x | x <- xs] :: Map String Int
The vertical bar is like "for" in Python's list comprehensions, "read"
is like int(str) except it converts to arbitrary datatypes, "words" is
like "split", and ":: Map String Int" is a type annotation that says
it's making a dictionary mapping strings to Ints. The Int type
signature tells "read" to convert to ints instead of floats or whatever. Finally, (a:b:_) binds the first two elements of x.split() and throws
away the rest.
I haven't tested the above so maybe I did something dumb. I haven't
written any Haskell in a while.
--- Synchronet 3.22a-Linux NewsLink 1.2