Dynamic alter-ego of D.

Gor Gyolchanyan gor.f.gyolchanyan at gmail.com
Wed Oct 26 07:42:09 PDT 2011


I know how opDispatch works. opDispatch is purely a syntax sugar (a
really neat one, IMO).
What I'm talking about is a way to choose between a set of functions,
based on the parameters.
It's basically dynamic overloading, but with additional ability to
overload, based on values (much like template constraints).
opDispatch, then could be a good way of hiding ugly code like
call("methodName", ...);

I never said, that i want this stuff to be built-in. THis is one of
those cool things, that many people could use as library solutions.
Such dynamic functions with powerful dynamic overloading and the help
of opDispatch would be an unprecedented awesome solution to event
handlers and callbacks.

On Wed, Oct 26, 2011 at 6:26 PM, Steven Schveighoffer
<schveiguy at yahoo.com> wrote:
> On Wed, 26 Oct 2011 10:15:33 -0400, Gor Gyolchanyan
> <gor.f.gyolchanyan at gmail.com> wrote:
>
>> 1. opDispatch is no good for overloading when the set of methods are
>> defined at run-time.
>
> For those cases, you must use the runtime interface that opDispatch will use
> directly.  D does not have a way to call a function by string at runtime.
>
> call("functionName", arg1, arg2, arg3)
>
> opDispatch simply provides a way to write cleaner code when you know the
> name of the function.
>
> Even in dynamic languages, it's uncommon to call functions based on runtime
> strings.
>
>> 2. opDIspatch doesn't cover operators (why?).
>
> operators are not function symbols, and are already covered by templates.
>  It should be as simple as:
>
> opBinary(string s, T...)(T args) if(isValidOperator!s)
> {
>   call(s, args);
> }
>
> -Steve
>


More information about the Digitalmars-d mailing list