A currying function

David Nadlinger see at klickverbot.at
Thu Jun 21 13:51:52 PDT 2012


On Thursday, 21 June 2012 at 19:04:32 UTC, Philippe Sigaud wrote:
> On Tue, Jun 19, 2012 at 2:52 PM, Artur Skawina
>> But, just to be able to say "Real Programmers don't use 
>> mixins": :)
>
> I find Bearophile version quite nice. I did something 
> equivalent a few
> years ago, with string mixins also. […]

Using string mixins as done here isn't just no »real 
programmers« thing to do, it has very substantial problems.

The problem with bearophile's code is that it uses T.stringof to 
refer to the parameter, but in the real world – where the 
template is not defined in the same module as it is used from – 
this will not work, as the (non-builtin) argument types will 
simply not be in scope (the implementation couldn't possibly 
import all the modules the user could ever want to use types 
from, even ignoring Voldemort types and the likes for the moment).

I see this mistake – __traits(identifier, …) has just the 
same problem, by the way – being made so frequently even by 
experienced D programmers (IIRC dranges contains a few instances 
of it as well) that I wonder if there is anything we could do 
about it design-wise. At least, adding a big warning on how to 
_not_ use stringof/__traits(identifier, …) to the language docs 
seems like a good idea to me.

Coming back to this particular case, the issue is very easy to 
fix: just emit ParameterTypeTuple!F[i] instead of T.stringof from 
the mixin generating code.

As far as ref is concerned, I'm not aware of a universal way to 
handle it in the general case – I usually end up manually 
looking ref-ness up to generate code accordingly (see 
ParameterStorageClassTuple).

David


More information about the Digitalmars-d mailing list