Functional programming in D and some reflexion on the () optionality.

Timon Gehr timon.gehr at gmx.ch
Mon Aug 6 14:36:38 PDT 2012


On 08/06/2012 09:33 PM, deadalnix wrote:
> Le 06/08/2012 20:15, Timon Gehr a écrit :
>>> To me, the first big failure of D to implement functional style is to
>>> not have first class functions.
>>
>> Last time I checked, D still had closures. The 'first big failure of D
>> to implement functional style' is the lack of most of the other
>> features traditionally encountered in functional languages.
>>
>
> I mentioned first class function. Functions are not first class, you
> have to go throw & .
>
>> Actually it is just that function declarations don't introduce symbols
>> that are bound to values of the first class type.
>>
>> Try enum foo = (){};
>>
>
> That is what I mean when I say that function are not first class.
>

What I mean when I say that functions are not first class is that there
are no first class functions. If functions are not first class there
eg. is no built-in way to pass a function to another function or
lexical closure does not work. Basing the decision on whether '&' is
required in some places is not useful.


>> &a.foo could be disallowed if foo is bound by UFCS.
>
> It wouldn't be more consistent and would limit expressiveness.

It can as well be allowed, because fields/properties of 'a' can behave
in a similar way. I don't really see what kind of consistency you aim
to preserve though.

This consistency argument feels to me like complaining about the fact
that &a.method returns a delegate while &a.field returns a pointer and
&a.property fails with a not an lvalue error.

>> The formalisation can formalise the behaviour in a compatible or mostly
>> compatible way. eg:
>> ...
>> Why would this be hard to implement?
>>
>
> Well it isn't straightforward, add @property into that and it become
> quite scary,

It is a bunch of syntactic rewrite rules. How hard can it be?

> now try to keep up with dmd that introduce changes into
> that process every release or so

I don't expect that to be the case.

> and you'll get my point.
>

What is this point? This feature is quite small and should be easy
to add even after almost all of the analysis implementation is finished
without spending much attention to it.


More information about the Digitalmars-d mailing list