File: lazy.rb

Project: Invitation to Ruby

#!/usr/bin/env ruby

def lazy_list_of_squares(n)
  [n*n, proc { lazy_list_of_squares(n+1) }]
end

list = lazy_list_of_squares(0)

10.times {
  puts list[0]
  list = list[1].call
}


[ Index ][ Table of Contents ]
Generated by [ source2html ]