Closures/Value capture: Difference between revisions

Content added Content deleted
(Updated second D entry)
(Promote from draft to full task status)
Line 1: Line 1:
{{draft task}}
{{task}}
'''Task:''' Create a list of 10 functions, in the simplest manner possible (anonymous functions are encouraged), such that the function at index <math>i</math> (you may choose to start <math>i</math> from either 0 or 1), when run, should return the square of the index, that is, <math>i^2</math>. Display the result of running any but the last function, to demonstrate that the function indeed remembers its value.
'''Task:''' Create a list of 10 functions, in the simplest manner possible (anonymous functions are encouraged), such that the function at index <math>i</math> (you may choose to start <math>i</math> from either 0 or 1), when run, should return the square of the index, that is, <math>i^2</math>. Display the result of running any but the last function, to demonstrate that the function indeed remembers its value.