From: Brian Candler Date: 2011-04-19T17:05:53+09:00 Subject: Re: anonymous closures with Proc,new, lambda and -> Stu wrote in post #993687: > I am new to the study of functional paradigm. If this question is > academic > please bear with me. > > How would I make this counter with lambda or -> without deferring to a > named > generator method or sigil var? Starting with the "named generator method": def make_counter(init) lambda { init += 1 } end Calling that method creates a new scope, and binds the value of 'init' within that scope. Now, you can do the same without def, by wrapping in another lambda: counter_maker = lambda { |init| lambda { init += 1 } } c = counter_maker.call(100) c.call # 101 c.call # 102 And you can do the same without explicitly binding 'counter_maker' either: c = lambda { |init| lambda { init += 1 } }.call(200) c.call # 201 c.call # 202 Is that what you were looking for? -- Posted via http://www.ruby-forum.com/.