D - alias declarations extension
- Manfred Nowak (37/37) Jan 11 2004 I just found:
- Ben Hinkle (12/48) Jan 11 2004 A problem with this proposal is that the alias is known at runtime but i...
- Sean L. Palmer (7/39) Jan 11 2004 Aliases work with types, everything else you mention works with variable...
I just found:
| If the designers of X-Windows built cars, there would be no fewer
| than five steering wheels hidden about the cockpit, none of which
| followed the same principles -- but you'd be able to shift gears
| with your car stereo. Useful feature, that. (Marcus J Ranum)
For D we have function pointers, delegates and of course variables that
can be declared in the module scope. Why should alias declarations
follow another principle?
I propose free aliases or alias variables:
<code>
module mod;
alias free; //free alias declared
void foo(char[] bom)
{
switch(bom){ //free alias defined here
case "utf8" : alias ubyte free; break;
case "utf16": alias wchar free; break;
case "utf32": alias dchar free; break;
default: alias char free; break;
};
}
void bar()
{
free c1; //free alias used
}
void xxx()
{
free c2; //free alias used
}
</code>
Of course, free aliases have the same problems as the other objects:
should be used however not before a defintion.
So long.
--
Fight Spam! Join EuroCAUCE: http://www.euro.cauce.org/
2EA56D6D4DC41ABA311615946D3248A1
Jan 11 2004
A problem with this proposal is that the alias is known at runtime but it
has to be compiled, so there is a chicken-and-egg problem. In other words,
how can the compiler compile bar() and xxx() when the value of the alias is
determined when foo() gets executed? For the example you give I support the
compiler could generate code for any possible alias and then at runtime
"pick" the right implementation, but that seems unworkable.
I think "version" is probably what you want. That is a compile-time switch
statement.
Am I misunderstanding the proposal?
-Ben
"Manfred Nowak" <svv1999 hotmail.com> wrote in message
news:btro1p$4tn$1 digitaldaemon.com...
I just found:
| If the designers of X-Windows built cars, there would be no fewer
| than five steering wheels hidden about the cockpit, none of which
| followed the same principles -- but you'd be able to shift gears
| with your car stereo. Useful feature, that. (Marcus J Ranum)
For D we have function pointers, delegates and of course variables that
can be declared in the module scope. Why should alias declarations
follow another principle?
I propose free aliases or alias variables:
<code>
module mod;
alias free; //free alias declared
void foo(char[] bom)
{
switch(bom){ //free alias defined here
case "utf8" : alias ubyte free; break;
case "utf16": alias wchar free; break;
case "utf32": alias dchar free; break;
default: alias char free; break;
};
}
void bar()
{
free c1; //free alias used
}
void xxx()
{
free c2; //free alias used
}
</code>
Of course, free aliases have the same problems as the other objects:
should be used however not before a defintion.
So long.
--
Fight Spam! Join EuroCAUCE: http://www.euro.cauce.org/
2EA56D6D4DC41ABA311615946D3248A1
Jan 11 2004
Aliases work with types, everything else you mention works with variables.
This kind of thing is not really possible in compiled languages. You need
to use a scripting language or entirely interpreted language (SmallTalk?) to
do such things.
Sean
"Manfred Nowak" <svv1999 hotmail.com> wrote in message
news:btro1p$4tn$1 digitaldaemon.com...
I just found:
| If the designers of X-Windows built cars, there would be no fewer
| than five steering wheels hidden about the cockpit, none of which
| followed the same principles -- but you'd be able to shift gears
| with your car stereo. Useful feature, that. (Marcus J Ranum)
For D we have function pointers, delegates and of course variables that
can be declared in the module scope. Why should alias declarations
follow another principle?
I propose free aliases or alias variables:
<code>
module mod;
alias free; //free alias declared
void foo(char[] bom)
{
switch(bom){ //free alias defined here
case "utf8" : alias ubyte free; break;
case "utf16": alias wchar free; break;
case "utf32": alias dchar free; break;
default: alias char free; break;
};
}
void bar()
{
free c1; //free alias used
}
void xxx()
{
free c2; //free alias used
}
</code>
Of course, free aliases have the same problems as the other objects:
should be used however not before a defintion.
Jan 11 2004









"Ben Hinkle" <bhinkle4 juno.com> 