A while ago, someone added an example with pure functions to Wikipedia's D article:

http://en.wikipedia.org/wiki/D_(programming_language)#Functional

Someone on the talk page asked why does the program compile despite that mySum accesses a variable in its enclosing function:

http://en.wikipedia.org/wiki/Talk:D_(programming_language)#Purity_of_mySum_function_in_the_.22Functional.22_section_.281.1.4.29

I replied with:

The code indeed compiles. I think that the idea is that nested functions have a hidden argument - a pointer to their enclosing scope (main's local variables). However, that doesn't explain why the code continues to compile when pivot is moved outside main(), or if you add a call to a non-pure function in mySum - these sound like compiler bugs.

I don't know much about purity, so I thought someone could shed some light on this?

--
Best regards,
 Vladimir                            mailto:[email protected]

Reply via email to