Talk:Closures/Value capture: Difference between revisions

m
(→‎Sample output: It's there.)
Line 11:
::The description "such that the function at index i (i from 0 to 9), when run, should return the number i." sounds like the function just returns its argument. It says nothing about how the return value behaves. It looks like we are meant to use a closure to create what is effectively a constant.
:::I misinterpreted this as its parametric position at first, but I think it means its position within a list. What happens if the list is as follows?: a(), b(), a(),
:::Should the first a() give 1, b() give 2, and the second a() give 3? [[User:Markhobley|Markhobley]] 12:06, 20 July 2011 (UTC)
:::: It seems to create a list of 10 elements with each element being a call to the same function bound to the index position. Which is why it struck me that it is using a closure to simulate a constant. (Mind you shuffling the list elements could then be fun). --[[User:Dgamey|Dgamey]] 13:09, 20 July 2011 (UTC)
:: Why 10 functions? Surely two or three would be sufficient to demonstrate how this works? The python example seems to put these in a list.
Anonymous user