Function pointers/delegates default args were stealth removed?
Carl Sturtivant
sturtivant at gmail.com
Mon Aug 27 01:33:27 PDT 2012
>
> The mangled names have a 1:1 correspondence with types. A
> mangled name can, for example, be reversed into a type.
>
> If default args form part of the type, then they'll have to be
> mangled in, too. This causes a rather long list of substantial
> problems.
The following has other pervasive ramifications, to say the
least. Worth thinking about IMHO nevertheless, even if to
eventually say "no". So here's a completely different way that
the effect of default arguments can be obtained without messing
with the type system.
Suppose a function pointer is always permitted be called with
fewer actual arguments than parameters declared. I'm speculating
uncritically here, so bear with me; this could be restricted to
calling function pointers & delegate pointers, or with an
avalanche of consequences permitted also for direct function
calling where it will interact with the overloading rules, or ...
there are many possible arrangements. So let's forge ahead for
now with the basic idea for function pointers.
Suppose a function pointer can be called with fewer actual
arguments than the number of parameters in its declaration.
Suppose that when such a call is made, the missing arguments will
always be assigned the default initialization for their types
(default default-arguments!). Now suppose that a language
mechanism is provided so that code in the function body can
determine how many actual arguments were supplied at the point of
call.
Now any function pointer can simulate other default arguments
(non-default default arguments) by testing the actual number of
arguments supplied and assigning defaults overtly to the
remainder inside the function body. No need for new types: this
is a run-time action.
Now you can stamp on this with big logic boots, but let's see if
I can escape from some of the trampling!
More information about the Digitalmars-d
mailing list