digitalmars.D.learn - dchar literals?
- Philippe Sigaud (7/7) Nov 10 2013 OK, maybe I'm slow today. Is there an easy way to write a dchar
- Jonathan M Davis (24/36) Nov 10 2013 I always do the cast, though honestly, I think that character literals s...
- bearophile (5/11) Nov 10 2013 I have added your idea to the bug report that I opened time ago:
- Philippe Sigaud (5/16) Nov 11 2013 OK, thanks. I'll go with the cast, as this way anyone reading the code w...
- bearophile (7/10) Nov 11 2013 99% of my char literals need to be of type char.
- Kenji Hara (8/18) Nov 12 2013 Or, uniform construction for built-in types would be another
- Jonathan M Davis (6/29) Nov 12 2013 That's more verbose, but it's something that I think we need anyway, an=
- bearophile (6/12) Nov 12 2013 Yes, uniform construction syntax for all types seems a good idea.
OK, maybe I'm slow today. Is there an easy way to write a dchar literal? I tend to use either: "a"d[0] or: cast(dchar)'a' Because 'a'd does not work...
Nov 10 2013
On Sunday, November 10, 2013 22:13:04 Philippe Sigaud wrote:OK, maybe I'm slow today. Is there an easy way to write a dchar literal? I tend to use either: "a"d[0] or: cast(dchar)'a' Because 'a'd does not work...I always do the cast, though honestly, I think that character literals should default to dchar rather than char. I'm not sure that we could ever talk Walter into that though, particularly if he thought that doing so would break code (I'm not sure whether it would or not, but using char for a character is almost always a bad idea, so defaulting to char for character literals just doesn't make sense to me). I'm not aware of there being a shorter way to get character literal to be dchar, though I suppose that if you had to do it a lot, you could create a function with a short name. e.g. dchar toDC(dchar d) { return d; } and end up with toDC('a') instead of cast(dchar)'a'; but I'd probably just use the cast. It certainly sounds like a nice enhancement though to be able to do 'a'd especially if the c and w versions gave errors when the character wouldn't fit in a char or wchar, which isn't the case with a cast. - Jonathan M Davis
Nov 10 2013
Jonathan M Davis:It certainly sounds like a nice enhancement though to be able to do 'a'd especially if the c and w versions gave errors when the character wouldn't fit in a char or wchar, which isn't the case with a cast.I have added your idea to the bug report that I opened time ago: https://d.puremagic.com/issues/show_bug.cgi?id=11103 Bye, bearophile
Nov 10 2013
On Sun, Nov 10, 2013 at 10:42 PM, Jonathan M Davis <jmdavisProg gmx.com>wrote:I always do the cast, though honestly, I think that character literals should default to dchar rather than char. I'm not sure that we could ever talk Walter into that though, particularly if he thought that doing so would break code (I'm not sure whether it would or not, but using char for a character is almost always a bad idea, so defaulting to char for character literals just doesn't make sense to me). I'm not aware of there being a shorter way to get character literal to be dchar, though I suppose that if you had to do it a lot, you could create a function with a short name. e.g.OK, thanks. I'll go with the cast, as this way anyone reading the code will be clear on what is happening there. And I agree with you than character literals should default to dchar. It's a perpetual source of friction for me.
Nov 11 2013
Philippe Sigaud:And I agree with you than character literals should default to dchar. It's a perpetual source of friction for me.99% of my char literals need to be of type char. On the other hand once you have suffixes to specify the char type, most of that problem vanishes, because writing 'x'c or 'x'w, 'x'd is good. Bye, bearophile
Nov 11 2013
On Monday, 11 November 2013 at 13:20:04 UTC, bearophile wrote:Philippe Sigaud:Or, uniform construction for built-in types would be another better way. auto c = char('a'); auto w = wchar('a'); auto d = dchar('a'); auto x = char('à'); // compile-time error Kenji HaraAnd I agree with you than character literals should default to dchar. It's a perpetual source of friction for me.99% of my char literals need to be of type char. On the other hand once you have suffixes to specify the char type, most of that problem vanishes, because writing 'x'c or 'x'w, 'x'd is good. Bye, bearophile
Nov 12 2013
On Tuesday, November 12, 2013 09:14:54 Kenji Hara wrote:On Monday, 11 November 2013 at 13:20:04 UTC, bearophile wrote:That's more verbose, but it's something that I think we need anyway, an= d it=20 might be enough to make it not worth adding the suffixes to character l= iterals. - Jonathan M DavisPhilippe Sigaud:=20 Or, uniform construction for built-in types would be another better way. =20 auto c =3D char('a'); auto w =3D wchar('a'); auto d =3D dchar('a'); =20 auto x =3D char('=C3=A0'); // compile-time errorAnd I agree with you than character literals should default to dchar. It's a perpetual source of friction for me.=20 99% of my char literals need to be of type char. =20 On the other hand once you have suffixes to specify the char type, most of that problem vanishes, because writing 'x'c or 'x'w, 'x'd is good. =20 Bye, bearophile
Nov 12 2013
Kenji Hara:Or, uniform construction for built-in types would be another better way. auto c = char('a'); auto w = wchar('a'); auto d = dchar('a'); auto x = char('à'); // compile-time errorYes, uniform construction syntax for all types seems a good idea. But the suffixes for chars, as the strings, could be a good idea any way, it's shorter, and it's symmetric with strings. Bye, bearophile
Nov 12 2013