Functional Programming with D

Kingsley via Digitalmars-d-announce digitalmars-d-announce at puremagic.com
Thu Aug 27 23:45:55 PDT 2015


On Sunday, 14 April 2013 at 15:27:29 UTC, Ali Çehreli wrote:
> On 04/13/2013 11:35 PM, qznc wrote:
>
> >> [...]
> talking about
> >>       [...]
> // in D
> >> [...]
> is similar to
> >>       [...]
> foo(const int *
> >>       [...]
> const ref d);
> >> [...]
> immutable.)
> >
> > The C variant is an mutable pointer to an immutable int. What
> is not to
> > know about that?
>
> What foo() does not know is whether the original int is const 
> or not:
>
>     int i = 0;
>     foo(&i);
>
>     // Can be mutated by the caller later on
>     i = 1;
>
> For that reason, function foo() cannot store the pointer 'c' in 
> confidence that it will not change in the future.
>
> Of course you and the dlang.org link that you have provided 
> indicate that immutable is not the same as const. When you say 
> "You can qualify variables as immutable, which is similiar to 
> C's const and Java's final, but it is transitive", it sounds 
> like the main difference that brings 'immutable' is 
> transitivity but I think the fact that data cannot be mutated 
> is the main difference. That makes it possible for a function 
> to request immutable data, something not possible in C because 
> a const reference parameter is not a requirement but a promise 
> not to mutate.
>
> And of course you never say they are the same; you say 
> "similar". Nothing is wrong with that. :)
>
> Ali

This is excellent information on functional programming with D. I 
would love to see a lot more information in this area - perhaps a 
much longer article covering in more detail - and also covering 
what is missing - e.g. does D have a for comprehension, Option, 
Either etc


More information about the Digitalmars-d-announce mailing list