- 论坛徽章:
- 0
|
原帖由 win_hate 于 2009-3-31 21:59 发表 ![]()
g=g
f b x y = if b then x else y
执行 g 会陷入无限循环。
f True 1 g 得到 1。
f False 1 g 无限循环。
这个并不能证明 lazy 的特性吧?
下面这个程序和这个差不多吧?
python:
- >>> def g():
- ... g()
- ...
- >>> def f(cond, a, b):
- ... if cond:
- ... return a
- ... else:
- ... b()
- ...
- >>> f(True, 5, g)
- 5
- >>> f(False, 5, g)
- Traceback (most recent call last):
- File "<stdin>", line 1, in <module>
- File "<stdin>", line 5, in f
- File "<stdin>", line 2, in g
- ...
- ...
- ...
- RuntimeError: maximum recursion depth exceeded
复制代码
[ 本帖最后由 izhier 于 2009-3-31 23:20 编辑 ] |
|