What purpose to const besides functional programming?
Fawzi Mohamed
fmohamed at mac.com
Wed Jul 23 20:08:36 PDT 2008
On 2008-07-24 03:33:41 +0200, Jason House <jason.james.house at gmail.com> said:
> 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.
yes but it has become clear that the way you use the term, and how
everybody else does is different, so it might be good to change your
definition, so that other understand you better.
> Invariant data: Data/bits that will never change. This can include data
> stored in ROM and other readonly memory.
yes
> 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)
different discussion
> Invariant functions:
> 1. (Current D definition) functions using invariant keyword
> e.g. int bar(int x) invariant{}
you agree that it makes sense to have functions that have some
arguments that are invariant?
Which syntax would you use to describe member functions whose this
argument is invariant?
> 2. (As I've been meaning it) Member functions of invariant data
> e.g. invariant T obj; obj.memberFunction();
member function of invariant data need to have the this argument that
is either const or invariant.
There are two kinds of them those that can have all sorts of side
effects (but obviously not modify the object), and those that have no
side effects (which we, as most other people call pure), the result of
these functions shares all the nice properties of invariant data (i.e.
you can basically treat a.x the same if x is a member variable or a
pure method with no other arguments returning a value of the same type).
Fawzi
More information about the Digitalmars-d
mailing list