do block, I pay attention to the variables captured by the closure. I tried some example in the manual and the previous discussions (like recent thread ) and found no
let needed in some cases. As I don’t know how long it takes to solve this issue completely, I was wondering if a whitelist/blacklist were helpful in current situation (it may seem trivial for advanced user I guess).
A whitelist (i.e., no additional coding like the
let tip needed)
- to capture the parameter in the enclosing scope of
do block like
... ... # no new assignment for r
... do x
This seems like a great use case for writing a macro. It should be possible to write a macro that takes a block like
let f=f, x=x, y=y, g=g
which would do what (I think) you’re looking for.
In particular, the
postwalk function from MacroTools.jl should make it much easier to walk through the whole expression while you gather up all the Symbols that need to be added to the
Really appreciate all the replies. I noticed that FastClosures is mentioned in the manual. However, in the most simple use case we need neither the
let block nor the macro at all. For two concrete examples
map(r) do x
y -> y * x
s = -r
map(r) do x
y -> y * x * s
So I came up with the idea of making a whitelist ((in a little genenal manner) of such use cases before the issue be solved 100% eventually. Hopefully there would be other cases that could be added into this whitelist for current v1.0. What do you think? Thanks!