What purpose to const besides functional programming?

Jason House jason.james.house at gmail.com
Wed Jul 23 18:33:41 PDT 2008


Walter Bright wrote:
> First we need to agree on what purity and invariance are.

Probably invariant functions too since I find myself using that term a lot.

Invariant data: Data/bits that will never change.  This can include data
stored in ROM and other readonly memory.

Pure functions: Function calls without side effects such that they can be
safely run in a multithreaded environment without synchronization.  Many
talk about input arguments to pure functions as being invarinat (thread
local storage or unique references and scoped access could be used to lift
that restriction, but I hope that's a different discussion)

Invariant functions:
 1. (Current D definition) functions using invariant keyword
    e.g. int bar(int x) invariant{}
 2. (As I've been meaning it) Member functions of invariant data
    e.g. invariant T obj;  obj.memberFunction();



More information about the Digitalmars-d mailing list