[Issue 5166] New: about D's template enhancement
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Nov 4 22:01:43 PDT 2010
http://d.puremagic.com/issues/show_bug.cgi?id=5166
Summary: about D's template enhancement
Product: D
Version: D2
Platform: Other
OS/Version: All
Status: NEW
Severity: enhancement
Priority: P1
Component: DMD
AssignedTo: nobody at puremagic.com
ReportedBy: galaxylang at gmail.com
--- Comment #0 from galaxylang <galaxylang at gmail.com> 2010-11-04 22:00:42 PDT ---
//i am a D's pursuer,this i think some about D's template,hope you can take a
look at it
//assume ! is right associate template apply operator,
//assume !! is template concat operator
//assume is(T:alias) traits function support
//i will show them as some sample
void twostepinstance()
{
//this is also a sample show depends resolve
struct A(U)
{
//step1: U is nothing,allowed
//step2: U is B!A
//for class A{},A seem as a symbol,but also can be seen as a type
//for class B(T){},B just a symbol
//is alias means it's a symbol
static if(is(U==alias))//step2,apply int,U!int=B!A!int
auto opCall(){return U!int();}
}
struct B(U)
{
}
alias B!A!B!A BABA;//because right associate,B!A!B!A==B!(A!(B!A)))
static if(is(BABA D==alias)
{
//D bind to sybmol B
}
BABA value;//BABA can be instance because A!() allowed
}
void listcompendium()
{
template ConcreteAble(L)
{
...
}
//template calac as functions
template Foreach_reverse(L)
{
static popFront()
{
alias Foreach_reverse!(L[0..$-1]) Foreach_reverse;
}
static top()
{
return L[$-1];
}
static empty()
{
return L.length==0;
}
}
template Reverse(L)
{
alias Foreach_reverse!(L) Reverse;
}
struct Struct(Any)
{
ConcreteAble!Any _;
}
//anyway,V is a list,for simply V==V[0] if V.length==1,compatible with D2
//needn't (...) comprehensive indication,just bind list to identity V
//V away can be concat by !! operator.example see bellow.
class A(V)
{
}
class B(U,V):A(V)
{
alias Struct!(U[0]!(Reverse!V))Revert;
}
//1.pay attention to C and typeof(C),the first can't be direct instanced
//2.[] as compendious of list,some time can be thrift
class C(V):B!([C,typeof(this)],V)
{
auto opCall()
{
return Revert();//why this syntax is not acceptable in D?
}
}
alias C!(int,long) ConcreteC;//same as C!([int,long]),[] was
thrift because C has only one templateparam T
//otherwise report confusion error
alias typeof(ConcreteC) OpResult;//Strcut!([long,int])
struct ImplicitCastable
{
long l;
int i;
}
//implicit copy struct if have same tuple
ImplicitCastable r=(new ConcreateC())();
}
void concatinstance
{
struct A(U)
{
U value;
}
alias A!int V1;
static if(version==VERSION2)
{
alias V1!!int V2;
V2 v2;//type of A!([int,int])
V1 v1;//type of A!([int]),list predigest
v2=v1;//warning but can copy
v1=v2;//error
}
//i think do it like this will reduce and simplify the template function if
provide,but not sure
template Concat(L)
{
alias L Concat;
}
alias Concat!int VI; //[int]==int
alias VI!!long VIL;//[int,long]
}
//I am care about D for a long time,i am sure D will be became the best system
program in the future,
//but also i would complain about the development mehtod.
//1.I think a fast prototype needed when D2 start,
//and use c is a bad choice,this recall me the development of perl,i am not
like perl,but perl6's
//delelopment method is worthy,we use rapidity prototype language a front and
gcc as it's end should be better.
//Even more,graph rewirte maybe the best choice,but i am not sure. C is not a
good language
//for quikly convergent bugs when requirement has not stable.
//2.I surguest import more functional style syntax and the stdlib should
reorgnizeation or delay sometime .
//3.And D for mobile is also needed,i think the mobile network will be the
futrue.
//I am now prepare for graduate examine,so i am not have enough time on
net.Beforetime,i
//have suggest for the concat instance syntax because i had got a good
ideal,but now i forgot it because
//poor of english and too many enlish worlds need me to remember :-: ,so i got
this one
//make up the number,not a good example.I only think a litte about template
because i am form cpp,which
//is surely a bad language :) for develop large program,and should be abondon
right now.
//Some time we need goto higher,then we think it,then the inspiration flash.
//For d hasn't too many people use it,change will influence fewer people,we
need make it perfect then the pursuer come.
//I now study quantum mechanics,i found the itself-contained,tangent and
presentational in quantum mechanics is same as
//our pursuance in develop progam and progam language, but i havn't more time
think about it right now.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list