On Friday, February 6, 2015 at 6:40:23 PM UTC+5:30, Devin Jeanpierre wrote: > Sorry for late reply, I somehow missed this email. > > On Thu, Feb 5, 2015 at 8:59 AM, Rustom Mody wrote: > > The reason I ask: I sorely miss haskell's pattern matching in python. > > > > It goes some way: > > > >>>> ((x,y),z) = ((1,2),3) > >>>> x,y,z > > (1, 2, 3) > > > > But not as far as I would like: > > > >>>> ((x,y),3) = ((1,2),3) > > File "<stdin>", line 1 > > SyntaxError: can't assign to literal > >>>> > > > > [Haskell] > > > > Prelude> let (x, (y, (42, z, "Hello"))) = (1, (2, (42, 3, "Hello"))) > > Prelude> (x,y,z) > > (1,2,3) > > Yeah, but Haskell is ludicrous. > > Prelude> let (x, 2) = (1, 3) > Prelude> > > Only non-falsifiable patterns really make sense as the left hand side > of an assignment in a language without exceptions, IMO. Otherwise you > should use a match/case statement. (Of course, Python does have > exceptions...)
Also its good to see the full context of your example: Prelude> let (x, 2) = (1, 3) Prelude> x *** Exception: <interactive>:2:5-19: Irrefutable pattern failed for pattern (x, 2) Prelude> So I am not sure what you find ludicrous. Haskell is a lazy language. This is lazy behavior. What else can it be? [Does not make me a great fan of laziness -- which is another matter] -- https://mail.python.org/mailman/listinfo/python-list