"Hiding" the mixin keyword?

renoX renosky at free.fr
Sat Feb 24 00:08:53 PST 2007


Reiner Pope a écrit :
> I don't think this is possible, but it certainly seems worthwhile to 
> support more advanced features through a standard function-call interface.
> 
> Andrei has been nagging Walter about this and making suggestions, so I 
> suppose we can hope it will be implemented sometime soon.

OK, thanks for your help, I'll stop wasting my time trying to get rid of 
the mixin() at the call site..
It's weird though: Reiner Pope in its 'Mixin demo: associative array 
initializers (with support for comments)' (digitalmars.D) did a mixin 
inside the associative array initialisation template, hiding the mixin, 
but I don't manage to do the same things.

> 
> renoX wrote:
>> What I would like is a way to 'hide' the mixin keyword, is-it possible 
>> to put into the template so that the result would look like:
>> putf!("Should be 31: %d{x+y+1}\n"); ?
> 
> I don't think it would be too hard to work out the details. What I can 
> think you might need is the following:

I'm not sure what you're saying here, but for the implementation look 
for 'Improvement on format strings, take two.' in digitalmars.D.

It treats differently const and non-const char[] thanks to a tip 
provided by mario pernici.

renoX
> 
>  1. The ability to specify that certain parameters in the list must be 
> compile-time constants, and the ability to overload by this.
>  2. Some kind of interface at the declaration site that specifies that 
> the return value of a given function be mixed into the code instead of 
> just treated as a value
> 
> The first one could look like this:
> 
>>
>> RegExpMatch matchRegexp(static char[] compileTimePattern, char[] 
>> text){...} // Parses the pattern at compile time
>> RegExpMatch matchRegexp(char[] runtimePattern, char[] text) {...} // 
>> Parses it at runtime
> 
> This would mean a library user wouldn't have to call a different 
> function to get the compile-time version than to get the runtime version.
> 
> The second would just involve adding some kind of modifier to a template 
> declaration, like the following:
> 
>> mixin template putf(A...)
>> {
>>     const char[] putf = ...;
>> }
>>
>> // Instantiated like:
>>
>> putf!("stuff");
>>
>> or
>>
>> mixin char[] putf(static char[] pattern)
>> {
>>     ...
>>     return generatedCode;
>> }
>>
>> // Instantiated like:
>>
>> putf("pattern %d{foo}");
>>
>> // with the return value mixed in
> 
> 
> This could also give you cool things, like the ability to mimic tuple's 
> compile-time indexing and make your own tuple wrapper:
> 
>>
>> struct MyTuple(A...)
>> {
>>     A data;
>>     typeof(A[i]) opIndex(static size_t i)
>>     {
>>         return data[i];
>>     }
>> }
> 
> 
> 
> Cheers,
> 
> Reiner


More information about the Digitalmars-d-learn mailing list