S
Stu
[Note: parts of this message were removed to make it a legal post.]
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
2
3
4
=> 4
error out on lambda
ArgumentError: wrong number of arguments(1 for 0)
...
and -> doesn't error but give undesired results:
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.
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
1closed = Proc.new( over=0){over+=1}=> # said:4.times { puts closed[] }
2
3
4
=> 4
error out on lambda
ArgumentError: wrong number of arguments(1 for 0)
...
and -> doesn't error but give undesired results:
1closed = ->( over=0){over+=1}=> # said:4.times { puts closed[] }
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.