You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
var P = function() {
return flip(theta) ? 'a' : 'b';
}
var fn = function() {
return sample(Beta({a: 1, b: 1}))
}
//var x = sample(Beta({a: 1, b: 1}));
var theta = 0.1;
theta;
var dist = Infer(
{method: 'MCMC', kernel: 'MH', samples: 1000},
P);
viz.auto(dist)
This code runs fine but when I uncomment the line initializing x, the code gives an error 'theta is not defined' . I am not sure how/why this is happening. Apologies if it isn't a bug.
The text was updated successfully, but these errors were encountered:
The way to make this work regardless of whether var x = ... is commented out or not, is to move var theta = ... to the top of the program. (Before theta is mentioned in P.)
I'm not sure whether we expect it to be possible to write var theta = ... after defining P and have things work, but that fact that this sometimes works and sometimes doesn't seems like a bug either way.
I am not sure how/why this is happening.
As part of compilation, the program is transformed into continuation passing style. When var x = sample(...) is present, everything after it appears inside a new function, and because that new function introduces a new scope theta isn't visible from P.
In other words, without the call to sample, the program generates JS something like this:
varP=function(){returntheta;};vartheta=100;P();
... but with the call to sample we get something like:
This code runs fine but when I uncomment the line initializing x, the code gives an error
'theta is not defined'
. I am not sure how/why this is happening. Apologies if it isn't a bug.The text was updated successfully, but these errors were encountered: