Arnar, yes indeed, that is a solution. That wouldn’t be usable in a pickle stream, however, since you cannot create functions in them.

]]>The problem with my_if is that it’s not lazy. You can use lambda to make it lazy:

```
def my_if(cond, then_val, else_val):
if cond:
return then_val()
else:
return else_val()
def factorial(n):
return my_if(n==1, lambda: 1, lambda: n * factorial(n-1))
```

```
>>> factorial(2)
2
>>> factorial(15)
1307674368000L
```

]]>This is exactly the kind of post I like to read.

]]>