Idea : Expression Type
Andrei Alexandrescu (See Website For Email)
SeeWebsiteForEmail at erdani.org
Fri Feb 2 13:35:16 PST 2007
Don Clugston wrote:
> Andrei Alexandrescu (See Website For Email) wrote:
>> Xinok wrote:
>>> Functions aren't powerful enough to be used in place of expressions.
>>>
>>> -- Functions can't return references, which prevents you from using
>>> them as l-values. The best you can do is return a pointer, which you
>>> have to manually dereference.
>>> -- All of the types in an expression are automatic, including the
>>> return type. Getting the parameter types for a function can be
>>> simple, but the return type can be difficult.
>>> -- Functions can't take full advantage of features like conditionals,
>>> because conditionals can have two or more possible 'return types'.
>>> Functions can only return a single type.
>>
>> Conditionals always have one return type that can be detected as
>> typeof(true? T : U).
>>
>> The advantage of expression aliases is that indeed there's no need to
>> worry for their type.
>
> That's already possible, albeit clumsy. You can duplicate the expression
> inside an anonymous delegate, and use D's automatic return type
> inference, together with an is( : return) expression. This works even
> when there are statements in the delegate, together with expressions.
>
> So I suspect something even more general might be possible.
Oh, yes, it's definitely possible. "Worrying about" does not mean "can't
do anything about" :o). It's just annoying. For example, half of
varargs_reduce deals with types, although it doesn't care about them at all.
A more general thing I was thinking of was to allow statements to bind
to aliases. Then D will have a pretty interesting macro mechanism.
Andrei
More information about the Digitalmars-d
mailing list