News for hackers. Stuff that matters.
Re:"I couldn't really learn Erlang, 'cos it didn't exist, so... by __alexs on Thursday January 24, 2013 @08:43AM (#5109421)
Python has closures, it just doesn't have a very convenient anonymous function syntax. I can't say I miss function () { .. } very often though.
Re:"I couldn't really learn Erlang, 'cos it didn't exist, so... by koide on Thursday January 24, 2013 @09:10AM (#5109554)
AFAIU Python's closure have been incomplete for a long time. I think they've become true, complete closures after the addition of the nonlocal keyword on 3.0

Please correct me if I'm mistaken. This all comes from a cursory research on the subject.

Re:"I couldn't really learn Erlang, 'cos it didn't exist, so... by btilly on Thursday January 24, 2013 @10:35AM (#5110016)
To my eyes they always were true and complete, but you had to play the minor trick of using mutable data to get them. Here is an example of what I mean that has worked forever.

  def outer ():
      counter = [0]
      def inner ():
          counter[0] += 1
          return counter[0]
      return inner
Re:"I couldn't really learn Erlang, 'cos it didn't exist, so... by klibertp on Thursday January 24, 2013 @10:49AM (#5110098)
I think I heard that this wasn't working around 2.0 or earlier... but I'm not curious enough to go research and I wasn't using Python until 2.4. Can you maybe confirm or deny this?
Re:"I couldn't really learn Erlang, 'cos it didn't exist, so... by btilly on Thursday January 24, 2013 @12:19PM (#5110712)
I've never heard that. I also did not use Python until 2.4.
Re:"I couldn't really learn Erlang, 'cos it didn't exist, so... by klibertp on Thursday January 24, 2013 @10:26AM (#5109971)
In short, in your opinion, Python has no "complete" closures because you cannot bind a new value to the name from enclosing lexical scope from within a nested scope. I disagree.
Re:"I couldn't really learn Erlang, 'cos it didn't exist, so... by effn on Thursday January 24, 2013 @11:26AM (#5110324)
This is not possible in Haskell either. You never hear people claiming Haskell doesn't support closures.
Re:"I couldn't really learn Erlang, 'cos it didn't exist, so... by klibertp on Thursday January 24, 2013 @11:42AM (#5110443)
Which is why I disagree with claims that Python doesn't support them either. It does, of course; we could argue if Python supports "complete" closures, but we won't, because we know better than to use meaningless terms in discussion, right?
Re:"I couldn't really learn Erlang, 'cos it didn't exist, so... by koide on Thursday January 24, 2013 @12:12PM (#5110667)
In any case it's not been the case in a while, so I stand corrected.

Although being able to write on the closed over variable is a neat feature to have, I would argue that feature does make a difference. Whether you call that complete or read-write or however you want to.

Re:"I couldn't really learn Erlang, 'cos it didn't exist, so... by pekk on Thursday January 24, 2013 @09:33AM (#5109662)
I like Python's scoping rules but declaring functions inline is a lot nicer and nicer-looking than defining functions starting with underscores.
Re:"I couldn't really learn Erlang, 'cos it didn't exist, so... by __alexs on Thursday January 24, 2013 @10:30AM (#5109987)
That is a false dichotomy. There are plenty of nice ways of working with closures with the given syntax.