Re:An accesible & intuitive layman's explanation of Bayes' T...
by nosignal on Monday September 05, 2011 @02:12AM
(#2961350)
Hey, thanks for that. Makes perfect sense. I definitely had an "oh is that all?" reaction.
I wish I could +1 you more than once for that, cheers! Now I get closures and bayesian reasoning, not bad for 2 days ;)
Now imagine you pass an integer around (as parameter, return value, bound to a name, or stored in a variable), surely you don't expect it to be modified behind your back? For instance:
So, `y` hasn't been modified behind your back. How is this possible? Well, there's 2 ways to see this: either(i) `y` was completely computed at the time it was defined. So, we grabbed the `x` that was in scope by the time we defined `y`, computed 40 + 2, and bam, we got 42. Of course, the value of 42 is not at all dependent on the value of the `x` name that is currently in scope.
(ii) `y` was not completely computed by the time it was defined, but only by the time we really really need it (here, at print time). But it still prints 42, not 2. The catch is, the value under `y` is made up of two things: the expression `x + 2`, and a key-value store, which will tell you the value of that `x` in the expression (here, that would be [("x", 40)]). Those two things do not change when you define a new x. And when you need to compute `y`, then you compute the expression, knowing that the above key-value store has the priority (you will see `x = 40` first, and won't bother to look up the other `x`, which has value `0`).
Functions work in exactly the same way. No trap. No trick. For instance, the program
will still print 42. Also, the two interpretations above still hold. Just remember that functions are values like any other.Now there are some caveats. If you allow side effects and it is not clear whether you enclose over values or over variables (or references), then some things may indeed be modified behind your back. (Imagine that the closure uses a key variable store where you thought it would be a key value store. Then it would be possible to change the content of the variables behind your back.) Anyway, my advice is to avoid side effects as much as you can[1].
[1]: http://www.loup-vaillant.fr/articles/assignment