Python 3000 in 60 seconds

After studying the relevant PEPs and other documents, I've come to the following conclusions:

  • Python 3000 used to be the mythical, revolutionary new release, implemented from scratch (possibly in C++), that would solve all of Python's problems, and then some.
  • However, over time, features that were originally intended for Python 3000 were added to the 2.x branch instead. (Actually, many of these were more like cleanups than new features. Fixing the class/type dichotomy, nested scopes, unifying longs and ints, division operator, etc.)
  • So, in 2008, Python 3000 is not quite so revolutionary anymore, compared to 2.5. As PEP 3000 says, "Python 3000 will be implemented in C, and the implementation will be derived as an evolution of the Python 2 code base. [...] Since Python 3000 as a language is a relatively mild improvement on Python 2, we can gain a lot by not attempting to reimplement the language from scratch."
  • In spite of that, Python 3000 is still special, because it introduces a number of changes that will break backward compatibility. Again, many of these deal with the fixing of warts and inconsistencies. For example: print will become a function; as and with will be keywords, and so will True, False and None; some functions (like map) now return iterators rather than lists; exception handling is different; etc. More here. (I will probably write about some of these changes in more detail later.)
  • Don't count on changes that will change the face of Python completely: explicit self and limited lambda are here to stay, not to mention indentation-based syntax and case sensitivity. (See PEP 3099.)

:: Comments (3)

Catamorphisms in 60 seconds

Catamorphisms. Recently I've seen this word popping up in some blog posts (often Haskell-related). Sounds fancy, and when I try to look it up, I run into stuff that is probably really deep, but looks like gobbledygook to me. (Likely because my brain doesn't really grok complex math stuff too well.)

What this word actually means is a technique where you take a number of values, process them in some way, and end up with fewer values (often a single one). A good example would be, computing the sum of a list of numbers.

In Python, one way to do this used to be using reduce (and that still works, but has been superseded by the sum built-in). Using this approach actually illustrates the concept well, known as folding in functional languages.

>>> numbers = [3, 6, 8, 12, -5]
>>> reduce(lambda x, y: x+y, numbers)
24

In other words, a catamorphism is just a fold. Oh, and the opposite (an "unfold") is called an anamorphism.

That's really all there is to it. (Of course, folding can and does get much more complex, but that's a different story.)

:: Comments (3)