From: Stu Date: 2011-04-19T15:07:53+09:00 Subject: anonymous closures with Proc,new, lambda and -> --485b3974781ef7c0e104a13f533a Content-Type: text/plain; charset=ISO-8859-1 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? my ruby version: % ruby -v ruby 1.9.2p180 (2011-02-18 revision 30907) my code examples for explanation: % irb >> closed = Proc.new( over=0){over+=1} => # >> 4.times { puts closed[] } 1 2 3 4 => 4 error out on lambda >> closed = lambda( over=0){over+=1} ArgumentError: wrong number of arguments(1 for 0) ... and -> doesn't error but give undesired results: >> closed = ->( over=0){over+=1} => # >> 4.times { puts closed[] } 1 1 1 1 => 4 in a named method I relize I can use a named method with argument being bound while returning with either -> or lamda. for example: def closure( over=0) lambda{over+=1} end def closure( over=0) ->{over+=1} end closed = closure both of these will work. I am just curious if there is a way to accomplish the same thing without method name definition i.e anonymous function. --485b3974781ef7c0e104a13f533a--