digitalmars.D - Value-parameters in templates (Bug?)
- Daniel Keep (17/17) Nov 17 2004 I think I might have found a(nother) bug :P
- Simon Buchan (7/25) Nov 17 2004 I suspect dmd is expecting only one argument for the function strCatMix(...
- Daniel Keep (10/42) Nov 17 2004 Well, it doesn't make any difference if I change the name of the
- Simon Buchan (20/62) Nov 17 2004 On Thu, 18 Nov 2004 01:16:04 +1100, Daniel Keep
- Regan Heath (19/27) Nov 17 2004 Try this:
- Lionello Lunesu (6/7) Nov 17 2004 Hi there.
- Regan Heath (22/29) Nov 17 2004 Yes, but..
- Nick (19/25) Nov 17 2004 It's hard to tell. The docs do not mention anything about it, but all th...
- Sean Kelly (31/47) Nov 17 2004 This is correct behavior. Since templates are evaluated at compile-time...
-
Carlos Santander B.
(30/30)
Nov 17 2004
"Daniel Keep"
escribió en el mensaje
I think I might have found a(nother) bug :P Compiling this with w/ dmd, I get: listtest.d(6): Error: integral type expected for value-parameter, not char[] As far as I can tell from the D website, this should be perfectly fine, as it doesn't mention anywhere that the value-parameter must be an int. Is the documentation just ambiguous, or is this not yet finished in the compiler? -- Daniel
Nov 17 2004
On Thu, 18 Nov 2004 00:50:34 +1100, Daniel Keep <daniel.keep dummy.gmail.com> wrote:I think I might have found a(nother) bug :P Compiling this with w/ dmd, I get: listtest.d(6): Error: integral type expected for value-parameter, not char[] As far as I can tell from the D website, this should be perfectly fine, as it doesn't mention anywhere that the value-parameter must be an int. Is the documentation just ambiguous, or is this not yet finished in the compiler? -- DanielI suspect dmd is expecting only one argument for the function strCatMix(), as you only gave one for the template. How are you expecting to use this? I dont know where dmd gets all its ints from, unfortunatly. -- Using Opera's revolutionary e-mail client: http://www.opera.com/m2/
Nov 17 2004
Well, it doesn't make any difference if I change the name of the function/template. Basically, it's for a functional library I'm toying with. It's used like this: alias strCatMix!(", ") StrCatComma; stdout.writeLine("["~StrReduce(&StrCatComma, someListOfStrings)~"]"); Or something like that :P As near as I can see, the number of parameters for the template doesn't have any bearing on the number of parameters in the function. -- Daniel Simon Buchan wrote:On Thu, 18 Nov 2004 00:50:34 +1100, Daniel Keep <daniel.keep dummy.gmail.com> wrote:I think I might have found a(nother) bug :P Compiling this with w/ dmd, I get: listtest.d(6): Error: integral type expected for value-parameter, not char[] As far as I can tell from the D website, this should be perfectly fine, as it doesn't mention anywhere that the value-parameter must be an int. Is the documentation just ambiguous, or is this not yet finished in the compiler? -- DanielI suspect dmd is expecting only one argument for the function strCatMix(), as you only gave one for the template. How are you expecting to use this? I dont know where dmd gets all its ints from, unfortunatly.
Nov 17 2004
On Thu, 18 Nov 2004 01:16:04 +1100, Daniel Keep <daniel.keep dummy.gmail.com> wrote: I think this is your problem: (from http://www.digitalmars.com/d/index.html, frame http://www.digitalmars.com/d/template.html) Implicit Template Properties If a template has exactly one member in it, and the name of that member is the same as the template name, that member is assumed to be referred to in a template instantiation: template Foo(T) { T Foo;// declare variable Foo of type T } void test() { Foo!(int) = 6;// instead of Foo!(int).Foo } Haven't any idea what using & on a template instance would do...Well, it doesn't make any difference if I change the name of the function/template. Basically, it's for a functional library I'm toying with. It's used like this: alias strCatMix!(", ") StrCatComma; stdout.writeLine("["~StrReduce(&StrCatComma, someListOfStrings)~"]"); Or something like that :P As near as I can see, the number of parameters for the template doesn't have any bearing on the number of parameters in the function. -- Daniel Simon Buchan wrote:-- Using Opera's revolutionary e-mail client: http://www.opera.com/m2/On Thu, 18 Nov 2004 00:50:34 +1100, Daniel Keep <daniel.keep dummy.gmail.com> wrote:I think I might have found a(nother) bug :P Compiling this with w/ dmd, I get: listtest.d(6): Error: integral type expected for value-parameter, not char[] As far as I can tell from the D website, this should be perfectly fine, as it doesn't mention anywhere that the value-parameter must be an int. Is the documentation just ambiguous, or is this not yet finished in the compiler? -- DanielI suspect dmd is expecting only one argument for the function strCatMix(), as you only gave one for the template. How are you expecting to use this? I dont know where dmd gets all its ints from, unfortunatly.
Nov 17 2004
On Thu, 18 Nov 2004 01:16:04 +1100, Daniel Keep <daniel.keep dummy.gmail.com> wrote:Well, it doesn't make any difference if I change the name of the function/template. Basically, it's for a functional library I'm toying with. It's used like this: alias strCatMix!(", ") StrCatComma; stdout.writeLine("["~StrReduce(&StrCatComma, someListOfStrings)~"]"); Or something like that :P As near as I can see, the number of parameters for the template doesn't have any bearing on the number of parameters in the function.Try this: import std.stdio; template test(T:T[],alias S) { char[] foo(T[] a, T[] b) { return a ~ S ~ b; } } char[] comma = ", "; alias test!(char[],comma).foo catComma; void main() { char[] a = "Heath"; char[] b = "Regan"; writef(catComma(a,b)); } Regan
Nov 17 2004
Hi there. Never wrote a D program in my life, but I've noticed that char[] is actually an array, so it's certainly not a "single value". What happens if you write (char* S =" "), then it's a value. D supports C-style pointers, right? Lionello.
Nov 17 2004
On Wed, 17 Nov 2004 16:11:58 +0200, Lionello Lunesu <lionello.lunesu crystalinter.remove.com> wrote:Yes, but.. import std.stdio; template test(char *S = ", ") { char[] foo(char[] a, char[] b) { return a ~ S ~ b; } } alias test!().foo catComma; void main() { char[] a = "Heath"; char[] b = "Regan"; writef(catComma(a,b)); } strcat.d(3): Error: integral type expected for value-parameter, not char* apparently 'char *' is not an integral type. Regan -- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/Hi there. Never wrote a D program in my life, but I've noticed that char[] is actually an array, so it's certainly not a "single value". What happens if you write (char* S =" "), then it's a value. D supports C-style pointers, right?
Nov 17 2004
In article <cnfkpe$ud3$1 digitaldaemon.com>, Daniel Keep says...[...] listtest.d(6): Error: integral type expected for value-parameter, not char[] As far as I can tell from the D website, this should be perfectly fine, as it doesn't mention anywhere that the value-parameter must be an int. Is the documentation just ambiguous, or is this not yet finished in the compiler?It's hard to tell. The docs do not mention anything about it, but all the given examples are ints. I also hope there will be support for other types in the future, since there doesn't seem to be any clear reason why value parameters should be restricted to integers. Here is the test case I used: It gives exactly the same error that you got. Nick
Nov 17 2004
In article <cnfkpe$ud3$1 digitaldaemon.com>, Daniel Keep says...I think I might have found a(nother) bug :P Compiling this with w/ dmd, I get: listtest.d(6): Error: integral type expected for value-parameter, not char[] As far as I can tell from the D website, this should be perfectly fine, as it doesn't mention anywhere that the value-parameter must be an int. Is the documentation just ambiguous, or is this not yet finished in the compiler?This is correct behavior. Since templates are evaluated at compile-time, you need to provide something that can be evaluated at compile-time such as an integer constant, etc. C++ allows you to use static arrays as template parameters like so: But D does not allow this. Instead you need to use an alias parameter: Note that this is functionally the same as the C++ approach, as the char array must be a static global variable. Sean
Nov 17 2004
"Daniel Keep" <daniel.keep dummy.gmail.com> escribió en el mensaje news:cnfkpe$ud3$1 digitaldaemon.com... |I think I might have found a(nother) bug :P | | | Compiling this with w/ dmd, I get: | | listtest.d(6): Error: integral type expected for value-parameter, not char[] | | As far as I can tell from the D website, this should be perfectly fine, | as it doesn't mention anywhere that the value-parameter must be an int. | Is the documentation just ambiguous, or is this not yet finished in | the compiler? | | -- Daniel From template.html (a couple of paragraphs below the grammar specification): "Template parameters can be types, values, or symbols. Types can be any type. Value parameters must be of an integral type, and specializations for them must resolve to an integral constant. Symbols can be any non-local symbol." ----------------------- Carlos Santander Bernal
Nov 17 2004