News for hackers. Stuff that matters.
Re:Python's Mutable Default Problem by neutronicus on Sunday February 20, 2011 @11:39AM (#2242255)
"a natural outcropping of python's late binding, "names are references" variable model, and closure mechanisms, which provide a consistency to the language that is often crufted up in others"

My mileage varies.

I'd prefer default parameters to honor referential transparency, whatever hoops the runtime has to jump through to make this happen.

Re:Python's Mutable Default Problem by jerf on Sunday February 20, 2011 @11:54AM (#2242288)
That would make that the only place in which Python has referential transparency, though. It may be a quirky side-effect of consistency, but it is consistent.
Re:Python's Mutable Default Problem by eru on Sunday February 20, 2011 @05:21PM (#2243329)
Strings are also non-mutable, and thus have referential transparency. And so do numbers in Python.
Re:Python's Mutable Default Problem by jerf on Monday February 21, 2011 @12:28AM (#2244374)
Referential transparency is a property of functions, not data (unless you're in a lambda mood and treat them as functions of zero arguments, but in that case you're not in Python so it's not relevant here). Even a function to "concatenate two strings" could be passed an object that overloads the addition operator to cause arbitrary modifications:

    >>> class Evil(object):
            def __init__(self):
                self.evil = 1
            def __add__(self, other):
                result = ("%s" % self.evil) + other
                self.evil += 1
                return result


    >>> def referentially_transparent_concat(a, b):
            return a + b

    >>> e = Evil()
    >>> print referentially_transparent_concat(e, "hi")
    1hi
    >>> print referentially_transparent_concat(e, "hi")
    2hi
You can program in a referentially-transparent style with Python, but you'll have to do it by adding your own restrictions to the code you write. Python will not help you with that.
Re:Python's Mutable Default Problem by eru on Friday February 25, 2011 @04:58PM (#2263948)
In your code the devil is in the data-type.