Fully transitive const is not necessary

Bill Baxter dnewsgroup at billbaxter.com
Wed Apr 2 13:25:02 PDT 2008


Steven Schveighoffer wrote:
> "Janice Caron" wrote in message

> The point is that logical const is still possible, even with transitive 
> const, because the global namespace is not const.  There is no way around 
> this except with pure functions.  Which I think you agree.
> 
> HOWEVER, the point that everyone is arguing is why does logical const make 
> pure functions or functional programming impossible?  Clearly, it is ALREADY 
> POSSIBLE to have logical const, and clearly, pure functions are possible! 
> I'm saying transitive const is mathematically equivalent to logical const 
> ALREADY.  Please try and grasp that concept.

Globals are a loophole.  Pure will close that loophole.  Allowing 
mutable members would be another loophole.  Maybe pure can just close 
that one too?  It would have to check that any access to a const object 
does not touch mutable fields.  It seems possible.  Would it be 
impossible for the compiler to check that for some reason?  Probably 
pure functions will only be able to call other pure functions, so that 
rules out the possibility of indirectly accessing mutable data via a 
function or method call.  So the only case that needs to be checked is 
directly referencing such a mutable field.

It does seem like something that could be tacked on after the rest of 
const/invariant/pure is done, though.  Much like C++'s mutable was.

--bb



More information about the Digitalmars-d mailing list