missing HexString documentation
Walter Bright
newshound2 at digitalmars.com
Thu Feb 8 18:25:12 UTC 2018
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.
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?
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 (!).
More information about the Digitalmars-d
mailing list