Idea : Expression Type

Don Clugston dac at nospam.com.au
Fri Feb 2 22:37:35 PST 2007


Andrei Alexandrescu (See Website For Email) wrote:
> 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.

Agreed. I think mixins were supposed to be a replacement for macros, but 
they're just too limited.

> 
> 
> Andrei



More information about the Digitalmars-d mailing list