Pure functions in D

Bent Rasmussen IncredibleShrinkingSphere at Gmail.com
Wed Sep 24 13:56:11 PDT 2008


I find invariant more natural and immutable more clumsy. On the other hand, 
why not make invariant the default and be done with it. The trend will go in 
that direction, the introduction of the entire const correctness stuff is an 
indication of where things are going. Better optimizable and safe by default 
than "invariant-with-effort".

Bent


"Brian Palmer" <d at brian.codekitchen.net> skrev i meddelelsen 
news:gb89pv$1l31$1 at digitalmars.com...
> bearophile Wrote:
>
>> >(Invariant means immutable.)<
>>
>> This specification, near the top of the article, that tells that a word 
>> means something else is a WARNING SIGN large as a wall that tells that 
>> that name is wrong and it has to change. Now I think D2 will sooner of 
>> later have to use the "immutable" word instead, as Python and Java 
>> communities too use.
>
> That's exactly what went through my head when I saw this line of the 
> article and I agree 100%, invariant needs to change to immutable in D2 
> before it becomes too late.
>
>> >A pure function can throw an exception (purity does not imply nothrow).<
>
> Since this wasn't touched on in the article, I want to point out that 
> Haskell allows "pure functions" to throw exceptions, but not catch them. 
> We need the same limitation in D2 pure functions -- since the exceptions 
> can only be caught in impure code, it's OK that the pure function threw 
> instead of returning. What can't happen is we can't have pure functions 
> catching exceptions, since they can then return a different value when, 
> for example, an out-of-memory exception is thrown.
>
> -- Brian 




More information about the Digitalmars-d mailing list