| [ next ] [ prev ] [ contents ] | Invitation To Ruby |
1: #!/usr/bin/env ruby
2:
3: def lazy_list_of_squares(n)
4: [n*n, proc { lazy_list_of_squares(n+1) }]
5: end
6:
7: list = lazy_list_of_squares(0)
8:
9: 10.times {
10: puts list[0]
11: list = list[1].call
12: }
|
0 1 4 9 16 25 36 49 64 81 |
| [ next ] [ prev ] [ contents ] | Copyright 2002 by Jim Weirich. All rights reserved. |