Hi,
i have a question about variable arguments in macros together with the scope of them.
Function count_test() should be a closure over the variable count and the lambda should be generated with a macro.
It should be possible to manipulate the count variable by sending a message (:inc or :dec), but the variable count will NOT change.
I did a macroexpand and the scope of count is NOT the Main, so the ESC was succesful. But anyway the count varibable do NOT change.
The example is from the book LetOverLambda Chapter 5.7.
Thanks
macro counter_macro(body...)
return quote
println("macro")
(msg) ->
begin
if $(body[1])[1] == msg
println("test inc")
$(esc(body[1]))[2] = $(esc(body[1]))[2] + 1
end
if $(body[2])[1] == msg
println("test dec")
$(esc(body[2]))[2] = $(esc(body[2]))[2] - 1
end
$(esc(body[2]))[2]
end
end
end
function count_test()
count = 0
return (@counter_macro [:inc count] [:dec count])
end
c2 = count_test()
c2(:inc)
c2(:inc)
c2(:inc)
c2(:dec)