missing HexString documentation
Steven Schveighoffer
schveiguy at yahoo.com
Thu Feb 8 18:42:51 UTC 2018
On 2/8/18 1:25 PM, Walter Bright wrote:
> On 2/8/2018 7:07 AM, Steven Schveighoffer wrote:
>> My concern in the hexString case is the sheer requirement of CTFE for
>> something that is so easy to do in the compiler, already *done* in the
>> compiler, and has another form specifically for hex strings (the
>> "\xde\xad\xbe\xef" form) that isn't going away. It makes me laugh
>> actually that Walter is now replacing the implementation with a mixin
>> of that other form, incurring all the cost of CTFE so you can
>> transform the string, while breaking existing code in the process:
>> https://github.com/dlang/phobos/pull/6138
>
> The breakage was due to the original implementation of hexString not
> producing a string literal like "abc", but producing an array literal
> like ['a', 'b', 'c'], which was not what the documentation said it did.
> And naturally, some uses wound up relying on the array behavior.
"abc" is an array (it's an immutable(char)[]). There's no reason why
['a','b','c'] should be different than "abc" (other than the hidden null
character, which is irrelevant here).
Perhaps the fact that using a string rather than an array causes code to
fail should be addressed?
>
> What the PR does is fix hexString so that hexString!"deadbeef" rewrites
> it to the string literal "\xde\xad\xbe\xef". It's classic "lowering".
> Isn't it amazing that D can even do this?
It's great that D has this power, and would be really useful if D's
language didn't already have a way to do this in a builtin way.
> Simplifying the compiler and pushing things off into the library makes
> the compiler and spec smaller and less buggy. It also has the nice
> feature of providing a simple path for anyone who wants to write their
> own custom string syntax, such as EBCDIC string literals (!).
How can this be a huge simplification? I mean you already have code that
parses hex characters in a string array, all you need is one flag that
assumes all character pairs have been preceded by \x. I think this will
save probably 4 or 5 lines of code?
It also doesn't preclude at all someone writing library code to make
their own custom string syntax.
-Steve
More information about the Digitalmars-d
mailing list