On 18/12/2010 12:46, Don wrote:
spir wrote:
On Sat, 18 Dec 2010 01:08:20 -0800
Jonathan M Davis <jmdavisp...@gmx.com> wrote:

Thank you for the explanation about strongly pure funcs calling weakly
pure ones --this fully makes sense.

I would like weakly pure to include output funcs, and exclude all
possibilities to modify (non-local) state.
The problem is that output is accessing global variables - which
weakly pure functions _cannot_ do.

Why? What is the rationale for excluding output (I don't mean I/O,
only O)?

You're correct in saying that it doesn't affect the operation of the
program. But in practice, program output is almost always important.

For example, suppose we allowed output to be pure. Then consider:

writeln("Hello, world!");

Since it returns nothing, and has no influence on the future execution
of the program, the writeln can be dropped from the program.

Hmmm....


Hum, it might still be useful to have something like a compiler switch that disables pure altogether, then people could use I/O and other non-pure operations for debugging purposes. One could wrap such code with a version statement:

void myPurefunc(Foo foo) pure {
  version(pure_disabled) {
    writeln("some debug info: ", foo);
  }
  //...


--
Bruno Medeiros - Software Engineer

Reply via email to