Counter with lambda syntax error

When I run this exercise:

def counter(start)
->(start) { start++ }
end

count = counter 0
(1…10).each do |i|
puts “#{count.call(i)}\n”
end

… I get this error:

ex1.rb:2: syntax error, unexpected ‘}’
ex1.rb:8: syntax error, unexpected end-of-input, expecting ‘}’

??

gvim

On Jan 13, 2014, at 11:43 AM, gvim [email protected] wrote:

When I run this exercise:

def counter(start)
->(start) { start++ }
end

There is no prefix or postfix increment operators in ruby.

Try it with:

start += 1

Regards,
Ammar

#closure for gvimrc | tr -d ‘g’

def make_counter( n) lambda { n += 1} end

first = make_counter 2
second = make_counter 42
first.()
3
second.()
43
second.()
44
first.()
4

(not (eq? p np))

lulz =)