Gen.jl icon indicating copy to clipboard operation
Gen.jl copied to clipboard

Side-effects of `@dist` functions take place at definition time

Open bzinberg opened this issue 5 years ago • 3 comments

Example:

julia> using Gen

julia> @dist function labeled_cat(weights, labels)
         println("$weights")
         labels[categorical(weights)]
       end;
Gen.SimpleArg{Any}(1)

bzinberg avatar Apr 30 '20 18:04 bzinberg

This appears to also apply if there is a macro invocation inside the function body that expands to something that has a dollar sign in it.

bzinberg avatar Apr 30 '20 18:04 bzinberg

I've been having quite a go at debugging this :slightly_smiling_face:

Looks like evaluation still works, so the issue is not a big deal. (Plus, it may already be documented that side effects are not expected, in which case I'm a dope)

bzinberg avatar Apr 30 '20 19:04 bzinberg

@bzinberg Maybe we can close this issue, after better documenting that the bodies of dist DSL functions should not have side effects?

marcoct avatar Jul 13 '21 13:07 marcoct