Purity

Don nospam at nospam.com
Sat Dec 18 04:46:11 PST 2010


spir wrote:
> On Sat, 18 Dec 2010 01:08:20 -0800
> Jonathan M Davis <jmdavisProg at 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....


More information about the Digitalmars-d mailing list