Function pointers/delegates default args were stealth removed?

Carl Sturtivant sturtivant at gmail.com
Mon Aug 27 05:55:34 PDT 2012


On Monday, 27 August 2012 at 12:14:30 UTC, Manu wrote:
> On 27 August 2012 14:08, Carl Sturtivant <sturtivant at gmail.com> 
> wrote:
>
>>
>>> extern(C) void function( ref const(Vector2) v0, ref 
>>> const(Vector2) v1,
>>> ref const(Vector2) v2, ref const(Color) color = Color.white, 
>>> BlendMode
>>> blendMode = BlendMode.Disabled ) fillTriangle2D;
>>>
>>
>> If function pointers could be called with fewer than the 
>> prototypical
>> number of arguments, and the remaining arguments be always 
>> initialized to
>> their .init defaults, you could perhaps make this sort of 
>> thing work
>> without the default argument values by using struct defaults.
>>
>> How would that be deficient?
>>
>
> ... no.
> Color does not .init == Color.white. You're suggesting I define 
> a new type,
> obscuring the API, every time I want a non-.init default arg?
> Also, I think it's correct that functions shouldn't be callable 
> without
> explicit parameters. Default args are carefully selected, and 
> they are
> always opt-in.
> 'v2' in this case shouldn't be allowed to default to [ NaN, NaN 
> ] if I omit
> it.

Yes, I am suggesting that to get the default you want you define 
a new (free at runtime) type. You need the D declaration of 
whichever C struct anyway, so this is that declaration with a 
default added. In a more complex situation aliasing can be used. 
For e.g. doubles, you can play a suitable struct game for once 
and for all, and use it repeatedly inside the D version of C 
structs. And I am suggesting the language definition be changed 
to allow calls of function pointers be made with some trailing 
arguments omitted.

If default arguments for function pointers are not available, 
except for the default defaults (.init), then what of this 
proposal?





More information about the Digitalmars-d mailing list