Quantcast
Channel: Chaos Folded
Viewing all articles
Browse latest Browse all 10

A reinterpretation of Python lists

$
0
0

I’m not a Python programmer and I only know the basics of the language, but what I never liked about it is its list handling. In general, just like C, Python is quite a boring language from a language-theoretic standpoint — a language to get the job done.

However, here is a supplemental piece of code implementing an alternative idea of lists for all the functional programmers of you, who are forced to use Python for whatever reason. Have fun, but beware: Your coworkers may not understand your code. ;)

Side note: A very annoying fact for me is that Python doesn’t support currying, but I found a somewhat ugly way to emulate it. Refer to the fix and range functions to see how it works.

Functional Church lists in Python

Update (Sun, 2009–02–08): I have refined the code and removed the fold function, since it’s really useless. Lists are higher order functions themselves, and the fold function was just a wrapper around them. I have also solved the currying problem, thanks to verte from #python on Freenode.


Viewing all articles
Browse latest Browse all 10

Trending Articles