December 02, 2003 Re: template instantiation (suggestion) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mark J. Brudnak | Sounds good. Sean "Mark J. Brudnak" <mjbrudna@oakland.edu> wrote in message news:bqgclt$2843$1@digitaldaemon.com... > IMO '$' should be reserved to denote the end of an array in the slice operation. > > SomeType array[ SOME_NUMBER ] ; > > array[0..$] ; /* slices the whole array */ > array[$-2..$] /* slices the last three elements */ > > Mark. |
December 02, 2003 Re: template instantiation (suggestion) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Patrick Down | Why cannot use simply instancetype(newinstancetype) and the compiler will know that, if instancetype is a "instance type", then it will instantiate it; and that's all In article <bqftct$1gqe$1@digitaldaemon.com>, Patrick Down says... > >In article <bqfm1p$14ks$1@digitaldaemon.com>, Andy Friesen says... >> >>Heretic wrote: >>> yo again. i`ve finally read the D language specification, lol. the more i read >>> bout d, the better it seems. however there`s one thing that annoys me. >>> templates have to be instantiated with the "instance Name(ARG)" expression... i >>> dont quite like it, wouldnt it be better to use Name<ARG> ? it is still context >>> independent and much faster to type, more comfortable and stuff. in c++ i have a >>> function alias_cast<T>(char*) that works as a object reference. i add aliases to >>> objects, but not aliases in teh D way. i name objects with character strings and >>> i`m able to access them this way. in D, i`d have to write instance >>> alias_cast(T).f(char*) whis is quite tedious to type and is less clear :/ >>> maybe i`m missing something, pls correct me then, but consider my suggestion of >>> using the triangular braces for template instantiation... >> >>The trouble with Name<ARG> is (as I understand it) that it requires semantic analysis to figure out whether < and > are being used as angle brackets, or as greater-than/less-than in an expression. >> >>Plain-old parenths might cut it, but that makes what's going on less obvious. Braces already have meaning as well. >> >>I agree that template instantiation should be much less verbose; it's just a matter of working out a good syntax for it. > >If we are going to keep explicit instantiation I think it would be good to replace the instance keyword with a symbol like '$' > >template Foo(Type) >{ >void Bar(Type a) { } >} > >$Foo(int).Bar(12); > >alias $Foo(int).Bar BarInt; > > > > > > > |
December 02, 2003 Re: template instantiation (suggestion) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Felix | Felix wrote:
>Why cannot use simply instancetype(newinstancetype) and the compiler will know
>that, if instancetype is a "instance type", then it will instantiate it; and
>that's all
>
>
This is my feeling on the matter to.
You mean like:
template Tfunc(T)
{
func(T) {}
}
...
Tfunc(int) X;
|
December 02, 2003 Re: template instantiation (suggestion) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Felix | Felix <Felix_member@pathlink.com> wrote in news:bqhfsl$p7k$1@digitaldaemon.com: > Why cannot use simply instancetype(newinstancetype) and the compiler will know that, if instancetype is a "instance type", then it will instantiate it; and that's all I agree that would be best. You will have to ask Walter but I belive the reason for the 'instance' keyword is to resolve some context sensitivity issue with the langauge grammer. |
December 02, 2003 Re: template instantiation (suggestion) | ||||
---|---|---|---|---|
| ||||
Posted in reply to J Anderson | Exactly. But I understand the current syntax if it is only experimental one. In article <bqhmes$13av$1@digitaldaemon.com>, J Anderson says... > >Felix wrote: > >>Why cannot use simply instancetype(newinstancetype) and the compiler will know that, if instancetype is a "instance type", then it will instantiate it; and that's all >> >> >This is my feeling on the matter to. > >You mean like: > >template Tfunc(T) >{ > func(T) {} >} > >... > >Tfunc(int) X; > |
December 02, 2003 Re: template instantiation (suggestion) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Felix | Felix wrote:
>Exactly. But I understand the current syntax if it is only experimental one.
>
>
>In article <bqhmes$13av$1@digitaldaemon.com>, J Anderson says...
>
>
>>Felix wrote:
>>
>>
>>
>>>Why cannot use simply instancetype(newinstancetype) and the compiler will know
>>>that, if instancetype is a "instance type", then it will instantiate it; and
>>>that's all
>>>
>>>
>>>
>>>
>>This is my feeling on the matter to.
>>
>>You mean like:
>>
>>template Tfunc(T)
>>{
>> func(T) {}
>>}
>>
>>...
>>
>>Tfunc(int) X;
>>
>>
>>
I do think Walter would have used the above syntax, if there wasn't some type of syntactical parsing difficulty. The D compiler is meant to be easy to replicate.
-Anderson
|
December 03, 2003 Re: template instantiation (suggestion) | ||||
---|---|---|---|---|
| ||||
Posted in reply to J Anderson | > I do think Walter would have used the above syntax, if there wasn't some type of syntactical parsing difficulty. The D compiler is meant to be easy to replicate. But at what cost, an cumbersome language ? C "J Anderson" <REMOVEanderson@badmama.com.au> wrote in message news:bqifev$2aef$1@digitaldaemon.com... > Felix wrote: > > >Exactly. But I understand the current syntax if it is only experimental one. > > > > > >In article <bqhmes$13av$1@digitaldaemon.com>, J Anderson says... > > > > > >>Felix wrote: > >> > >> > >> > >>>Why cannot use simply instancetype(newinstancetype) and the compiler will know > >>>that, if instancetype is a "instance type", then it will instantiate it; and > >>>that's all > >>> > >>> > >>> > >>> > >>This is my feeling on the matter to. > >> > >>You mean like: > >> > >>template Tfunc(T) > >>{ > >> func(T) {} > >>} > >> > >>... > >> > >>Tfunc(int) X; > >> > >> > >> > I do think Walter would have used the above syntax, if there wasn't some type of syntactical parsing difficulty. The D compiler is meant to be easy to replicate. > > -Anderson > |
December 03, 2003 Re: $ as array end token (was template instantiation) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mark Brudnak | Mark Brudnak wrote:
> What about the case:
>
> array[$-2..$] /* slices the last three elements */
array[-2..]
with the limitation, that this minus may not be a part of the argument, but only a unary minus. Hell, make it a "[-"-operator! A negative value of arguments should be still out-of-bounds error.
-eye
|
December 03, 2003 Re: template instantiation (suggestion) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ant | In article <bqgdrs$29u1$1@digitaldaemon.com>, Ant says... > >In article <bqgclt$2843$1@digitaldaemon.com>, Mark J. Brudnak says... >> >>IMO '$' should be reserved to denote the end of an array in the slice operation. >> >>SomeType array[ SOME_NUMBER ] ; >> >>array[0..$] ; /* slices the whole array */ >>array[$-2..$] /* slices the last three elements */ >> >>Mark. > >IMO you opinion is realy cool. > >Ant IMO why not use the same syntax as Python? array[:] a slice of the whole array array[-5:] last five elements array[:-5] all but last five Also D should have this: In article <bqgdrs$29u1$1@digitaldaemon.com>, Ant says... > >In article <bqgclt$2843$1@digitaldaemon.com>, Mark J. Brudnak says... >> >>IMO '$' should be reserved to denote the end of an array in the slice operation. >> >>SomeType array[ SOME_NUMBER ] ; >> >>array[0..$] ; /* slices the whole array */ >>array[$-2..$] /* slices the last three elements */ >> >>Mark. > >IMO you opinion is realy cool. > >Ant IMO use the same syntax as Python, skip the perlin noise? or use .. if you insist ;-) but it's two keypresses rather than 1 array[:] // a slice of the whole array array[-5:] // last five elements array[:-5] // all but last five And D should also have this: some = array[-2] //next to last component this is absolutely beautiful if you have a circular list or something and have to do something based on other members. /* foreach(int i, inout float f; a) { //this will overstep the bounds so we need a special case for the last two f = (a[i+1] + a[i+2])*0.5 } */ foreach(int i, float f; a) { //instead we start at the next to latest a[i-2] = (a[i-1] + a[i])*0.5 } Nonni |
December 03, 2003 Re: template instantiation (suggestion) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sean L. Palmer | Tangenting the issue, I just recently realized (maybe it was crystal-clear to everybody else, but what the heck) that representing half-open ranges, which was proposed some time earlier, actually wouldn't be completely impossible. array[a .. b) // for (int i=a; i<b; ++i) array[a .. b] // for (int i=a; i<=b; ++i) array(a .. b) // for (int i=a+1; i<b; ++i) array(a .. b] // for (int i=a+1; i<=b; ++i) I for some reason thought that the language grammar couldn't allow [ and ) to match. Silly me. Just requires adding the proper grammar productions: PostfixExpression [ Expression ) PostfixExpression [ Expression ] PostfixExpression ( Expression ) PostfixExpression ( Expression ] Ok, so it might conflict a bit with the function call syntax. And would probably cause a lot of nice off-by-one bugs because ( and [ look the same. So we may probably forget it :) -Antti In article <bqh9vd$h48$1@digitaldaemon.com>, Sean L. Palmer wrote: > Sounds good. *nods* > > Sean > > "Mark J. Brudnak" <mjbrudna@oakland.edu> wrote in message news:bqgclt$2843$1@digitaldaemon.com... >> IMO '$' should be reserved to denote the end of an array in the slice operation. >> >> SomeType array[ SOME_NUMBER ] ; >> >> array[0..$] ; /* slices the whole array */ >> array[$-2..$] /* slices the last three elements */ >> >> Mark. > > |
Copyright © 1999-2021 by the D Language Foundation