www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Type.stringof

reply Michiel <nomail please.com> writes:
The documentation sais that all types should have the property
.stringof, but it doesn't seem to work. Has it been renamed? Or doesn't
it exist (anymore)?

Thanks,

-- 
Michiel
Feb 21 2007
parent reply Walter Bright <newshound digitalmars.com> writes:
Michiel wrote:
 The documentation sais that all types should have the property
 .stringof, but it doesn't seem to work. Has it been renamed? Or doesn't
 it exist (anymore)?
In what case does it not work?
Feb 22 2007
parent reply Michiel <nomail please.com> writes:
Walter Bright wrote:

 The documentation sais that all types should have the property
 .stringof, but it doesn't seem to work. Has it been renamed? Or doesn't
 it exist (anymore)?
In what case does it not work?
Any case. I tried this: ------------------------------------------ module test; import std.stdio; struct Foo { } enum Enum { RED } typedef int myint; void main() { writefln((1+2).stringof); // "1 + 2" writefln(Foo.stringof); // "Foo" writefln(test.Foo.stringof); // "test.Foo" writefln(int.stringof); // "int" writefln((int*[5][]).stringof); // "int*[5][]" writefln(Enum.RED.stringof); // "Enum.RED" writefln(test.myint.stringof); // "test.myint" writefln((5).stringof); // "5" } ------------------------------------------ And got these errors: ------------------------------------------ main.d(13): Error: no property 'stringof' for type 'int' main.d(14): Error: no property 'stringof' for type 'Foo' main.d(15): Error: no property 'stringof' for type 'Foo' main.d(16): Error: no property 'stringof' for type 'int' main.d(17): Error: no property 'stringof' for type 'int*[5][]' main.d(18): Error: no property 'stringof' for type 'int' main.d(19): Error: no property 'stringof' for type 'int' main.d(20): Error: no property 'stringof' for type 'int' ------------------------------------------ -- Michiel
Feb 22 2007
parent reply Lionello Lunesu <lio lunesu.remove.com> writes:
Michiel wrote:
 Walter Bright wrote:
 
 The documentation sais that all types should have the property
 .stringof, but it doesn't seem to work. Has it been renamed? Or doesn't
 it exist (anymore)?
In what case does it not work?
Any case. I tried this: ------------------------------------------ module test; import std.stdio; struct Foo { } enum Enum { RED } typedef int myint; void main() { writefln((1+2).stringof); // "1 + 2" writefln(Foo.stringof); // "Foo" writefln(test.Foo.stringof); // "test.Foo" writefln(int.stringof); // "int" writefln((int*[5][]).stringof); // "int*[5][]" writefln(Enum.RED.stringof); // "Enum.RED" writefln(test.myint.stringof); // "test.myint" writefln((5).stringof); // "5" }
That works just fine here, DMD 1.007 L.
Feb 22 2007
parent reply Michiel <nomail please.com> writes:
Lionello Lunesu wrote:

 The documentation sais that all types should have the property
 .stringof, but it doesn't seem to work. Has it been renamed? Or doesn't
 it exist (anymore)?
In what case does it not work?
Any case. I tried this:
That works just fine here, DMD 1.007
Ah, I have DMD 1.003. Would that make the difference? -- Michiel
Feb 22 2007
parent reply Deewiant <deewiant.doesnotlike.spam gmail.com> writes:
Michiel wrote:
 Lionello Lunesu wrote:
 
 The documentation sais that all types should have the property
 .stringof, but it doesn't seem to work. Has it been renamed? Or doesn't
 it exist (anymore)?
In what case does it not work?
Any case. I tried this:
That works just fine here, DMD 1.007
Ah, I have DMD 1.003. Would that make the difference?
Seeing as .stringof was added in DMD 1.005, it might. ;-) -- Remove ".doesnotlike.spam" from the mail address.
Feb 22 2007
next sibling parent reply Michiel <nomail please.com> writes:
Deewiant wrote:

 The documentation sais that all types should have the property
 .stringof, but it doesn't seem to work. Has it been renamed? Or doesn't
 it exist (anymore)?
In what case does it not work?
Any case. I tried this:
That works just fine here, DMD 1.007
Ah, I have DMD 1.003. Would that make the difference?
Seeing as .stringof was added in DMD 1.005, it might. ;-)
Strange. It wasn't even so long ago that I downloaded the compiler. Has stringof only existed for a month or so? -- Michiel
Feb 22 2007
next sibling parent reply Lionello Lunesu <lio lunesu.remove.com> writes:
Michiel wrote:
 Deewiant wrote:
 
 The documentation sais that all types should have the property
 .stringof, but it doesn't seem to work. Has it been renamed? Or doesn't
 it exist (anymore)?
In what case does it not work?
Any case. I tried this:
That works just fine here, DMD 1.007
Ah, I have DMD 1.003. Would that make the difference?
Seeing as .stringof was added in DMD 1.005, it might. ;-)
Strange. It wasn't even so long ago that I downloaded the compiler. Has stringof only existed for a month or so?
17 days to be exact :)
Feb 22 2007
parent BCS <BCS pathlink.com> writes:
Lionello Lunesu wrote:
 Michiel wrote:
 
 Deewiant wrote:

 The documentation sais that all types should have the property
 .stringof, but it doesn't seem to work. Has it been renamed? Or 
 doesn't
 it exist (anymore)?
In what case does it not work?
Any case. I tried this:
That works just fine here, DMD 1.007
Ah, I have DMD 1.003. Would that make the difference?
Seeing as .stringof was added in DMD 1.005, it might. ;-)
Strange. It wasn't even so long ago that I downloaded the compiler. Has stringof only existed for a month or so?
17 days to be exact :)
The bleeding edge doesn't last vary long around here. <g>
Feb 22 2007
prev sibling parent reply Max Samukha <samukha voliacable.com> writes:
On Thu, 22 Feb 2007 14:33:00 +0100, Michiel <nomail please.com> wrote:

Deewiant wrote:

 The documentation sais that all types should have the property
 .stringof, but it doesn't seem to work. Has it been renamed? Or doesn't
 it exist (anymore)?
In what case does it not work?
Any case. I tried this:
That works just fine here, DMD 1.007
Ah, I have DMD 1.003. Would that make the difference?
Seeing as .stringof was added in DMD 1.005, it might. ;-)
Strange. It wasn't even so long ago that I downloaded the compiler. Has stringof only existed for a month or so?
Yes, it has not been announced as part of the language. Walter said it was because it didn't work correctly. And it really doesn't, at least for enums. For example, this gives int while Test is expected: enum Test : int { one } void main() { pragma (msg, Test.stringof); }
Feb 22 2007
parent Michiel <nomail please.com> writes:
Max Samukha wrote:

 The documentation sais that all types should have the property
 .stringof, but it doesn't seem to work. Has it been renamed? Or doesn't
 it exist (anymore)?
In what case does it not work?
Any case. I tried this:
That works just fine here, DMD 1.007
Ah, I have DMD 1.003. Would that make the difference?
Seeing as .stringof was added in DMD 1.005, it might. ;-)
Strange. It wasn't even so long ago that I downloaded the compiler. Has stringof only existed for a month or so?
Yes, it has not been announced as part of the language. Walter said it was because it didn't work correctly. And it really doesn't, at least for enums. For example, this gives int while Test is expected:
Well, it's handy nonetheless. I'm using it in some assert(0) error messages. Thanks for the help, everyone. I'll update the compiler. -- Michiel
Feb 22 2007
prev sibling parent reply torhu <fake address.dude> writes:
Deewiant wrote:
 Michiel wrote:
 Ah, I have DMD 1.003. Would that make the difference?
 
Seeing as .stringof was added in DMD 1.005, it might. ;-)
I think that it would be good if the docs could mention with which compiler version a feature was added.
Feb 22 2007
parent reply Walter Bright <newshound digitalmars.com> writes:
torhu wrote:
 I think that it would be good if the docs could mention with which 
 compiler version a feature was added.
It does in the changelog.
Feb 22 2007
parent reply Lionello Lunesu <lio lunesu.remove.com> writes:
Walter Bright wrote:
 torhu wrote:
 I think that it would be good if the docs could mention with which 
 compiler version a feature was added.
It does in the changelog.
Not for .stringof it doesn't :) By the way, it would be nice if .stringof for an enum member would return the actual enum stringized. Will this be possible? L.
Feb 22 2007
next sibling parent Leandro Lucarella <llucarella integratech.com.ar> writes:
Lionello Lunesu escribió:
 Walter Bright wrote:
 torhu wrote:
 I think that it would be good if the docs could mention with which 
 compiler version a feature was added.
It does in the changelog.
Not for .stringof it doesn't :) By the way, it would be nice if .stringof for an enum member would return the actual enum stringized. Will this be possible?
And it's not very practical to read the doc and searching the changelog to see where that particular feature where added. -- Leandro Lucarella Integratech S.A. 4571-5252
Feb 22 2007
prev sibling parent renoX <renosky free.fr> writes:
Lionello Lunesu a écrit :
 Walter Bright wrote:
 torhu wrote:
 I think that it would be good if the docs could mention with which 
 compiler version a feature was added.
It does in the changelog.
Not for .stringof it doesn't :) By the way, it would be nice if .stringof for an enum member would return the actual enum stringized.
Note that Kevin Bealer has made two versions of a template for 'reflective enums'. I don't find the result totally satisfying as you loose the type safety in current version, but it's a good start. renoX
 Will this be possible?
 
 L.
Feb 22 2007