In the following pseudocode, is it possible to drop the foo
quote inside the fizzbuzz
function?
bar = quote
foo = quote
i = rand()
j = 7
end
function fizzbuzz()
# want foo here
k = i * j
end
end
For clarity, the following works with foo
defined outside the bar
quote:
foo = quote
i = rand()
j = 7
end
bar = quote
function fizzbuzz()
$(foo)
k = i * j
end
end
bar = quote
foo = quote
i = rand()
j = 7
end
function fizzbuzz()
eval($foo)
k = i*j
end
end
eval
won’t work because it operates on a module scope (i.e. it won’t have access to function variables)
Another try:
This also avoids foo
to be expanded too early. But bar
now does not express the function fizzbuzz
, but yet another expression, so maybe this won’t work for you either. (Actually, it is more or less the same as the working version that you wrote initially, but wrapped into another expression.)
bar = quote
foo = quote
i = rand()
j = 7
end
quote
function fizzbuzz()
$foo;
k = i*j
end
end
end
1 Like
Solid effort, but the real answer I guess was that you have to flip the problem on its head?
The way I got around this situation is copying the work of InteractNext.jl