Yes for security reasons I want to make sure a function does not access anything beyond its "lexical variables declared within the function scope" (Thank you BrowserUk). Basicly I want to write pure functions that will throw a compile-time error when they are not pure. | [reply] |
Basicly I want to write pure functions that will throw a compile-time error when they are not pure.
Your definition of 'pure' is different from my definition of 'pure'.
A 'pure' (as in functional programming) function ~can~ use external variables and still be called pure. It must not modify these variables, but it would be perfectly fine to have a sin(x) where you provide π as an external value. Changing π will change the actual output value, but if you repeat the calculation it will a) result in the same output value and b) x and π will not be modified.
| [reply] |
| [reply] |
I want to write pure functions that will throw a compile-time error when they are not pure.
Could you explain why?
| [reply] |
I'll need to check out Safeand its family, as they may have addressed the problem.
My current thought would be to develop each function (presuming this is synonymous with a Perl subroutine in this context) initially as a stand-alone file, with use strict;and use warnings;at the top and a calling routine built in.
If it compiles without errors, there are no external references.
Then a quick process to extract only the subroutine into your main code and you're off to the races.
The weakness is that if one bypasses the build procedure, one can violate the constraint.
| [reply] [d/l] [select] |