list storing variables

Marko Rauhamaa marko at pacujo.net
Mon Feb 23 15:38:40 EST 2015


Ian Kelly <ian.g.kelly at gmail.com>:

> Obviously one can use any Turing-complete language to emulate features
> of any other Turing-complete language, but I think the point is that
> there is no syntactic support for it.

While my "contribution" was made tongue-in-cheek, there's a grain of
truth in every joke.

First of all, this is not emulating a Turing-complete language. It is
demonstrating differences in the data model. The differences aren't in
the supposed absence of variables or memory slots. Python has variables
that are memory slots, just like C or Java.

You are right that Python doesn't have syntactic support for "&".
However, that has little bearing to the underlying data model.

Python doesn't suffer from the absence of "&" as much as Java does, for
example, because its main use case is returning multiple values. Tuples
handle that just fine -- although, look at this snippet:

    def put_left(self, key, value):
        if self.left is None:
            self.left = Entry(self, key, value)
            self.balance -= 1
            return self, self.right is None, self.left, True
        self.left, grown, entry, fresh = self.left.put(key, value)
        if not grown:
            return self, False, entry, fresh
        self.balance -= 1
        if self.balance != -2:
            return self, self.balance == -1, entry, fresh
        return self.rotate_right(), False, entry, fresh


There are other, rarer use cases where idioms such as my AmpersandA
class need to be employed. But, thanks to the existence of closures, no
tears are shed.


Marko



More information about the Python-list mailing list