5 ms·
That's the problem. I can fake a functional paradigm within Python in some settings, but it falls apart at the seams.
by chimeracoder 14y ago
That's the problem. I can fake a functional paradigm within Python in some settings, but it falls apart at the seams.
- groovy2shoes 14y agoYou can always use 2-tuples to get lists in the Lisp sense. You'd add an item to the head of a list by just pairing it: lst = (2, (3, ())) newlst = (1, lst) Toss in some small helper functions and they become less unwieldy. You could pretty easily write an iterator for processing these lists: class List: def __init__(self, lst): self.cursor = lst def __iter__(self): return self def next(self): if self.cursor == (): raise StopIteration else: head = self.cursor[0] self.cursor = self.cursor[1] return head Then you can do stuff like: >>> for i in List(newlst): ... print i ... 1 2 3 >>> map(lambda x: x + 1, List(newlst)) [2, 3, 4]