February 07, 2018 missing HexString documentation | ||||
---|---|---|---|---|
| ||||
It is mentioned in the literals section, but not documented: https://dlang.org/spec/lex.html#string_literals From reading forum posts I managed to figure out that HexStrings are prefixed with an x. i.e. x"deadbeef" |
February 07, 2018 Re: missing HexString documentation | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ralph Doncaster | On 2/7/18 9:59 AM, Ralph Doncaster wrote: > It is mentioned in the literals section, but not documented: > https://dlang.org/spec/lex.html#string_literals > > From reading forum posts I managed to figure out that HexStrings are prefixed with an x. i.e. x"deadbeef" > Good catch! Even the grammar says nothing about what it is, except it has HexString as a possible literal. Can you file an issue? https://issues.dlang.org -Steve |
February 07, 2018 Re: missing HexString documentation | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | On Wednesday, 7 February 2018 at 15:25:05 UTC, Steven Schveighoffer wrote: > On 2/7/18 9:59 AM, Ralph Doncaster wrote: >> It is mentioned in the literals section, but not documented: >> https://dlang.org/spec/lex.html#string_literals >> >> From reading forum posts I managed to figure out that HexStrings are prefixed with an x. i.e. x"deadbeef" >> > > Good catch! Even the grammar says nothing about what it is, except it has HexString as a possible literal. > > Can you file an issue? https://issues.dlang.org > > -Steve They are deprecated: https://dlang.org/changelog/pending.html#hexstrings https://dlang.org/deprecate.html#Hexstring%20literals Hence, the grammar has been incompletely updated. As it's not an error to use them now, it should have stated that they are deprecated. Anyhow, you can always go back in time: https://docarchives.dlang.io/v2.078.0/spec/lex.html#HexString |
February 07, 2018 Re: missing HexString documentation | ||||
---|---|---|---|---|
| ||||
Posted in reply to Seb | On Wednesday, 7 February 2018 at 15:41:37 UTC, Seb wrote:
> On Wednesday, 7 February 2018 at 15:25:05 UTC, Steven Schveighoffer wrote:
>> On 2/7/18 9:59 AM, Ralph Doncaster wrote:
>>> It is mentioned in the literals section, but not documented:
>>> https://dlang.org/spec/lex.html#string_literals
>>>
>>> From reading forum posts I managed to figure out that HexStrings are prefixed with an x. i.e. x"deadbeef"
>>>
>>
>> Good catch! Even the grammar says nothing about what it is, except it has HexString as a possible literal.
>>
>> Can you file an issue? https://issues.dlang.org
>>
>> -Steve
>
> They are deprecated:
>
> https://dlang.org/changelog/pending.html#hexstrings
> https://dlang.org/deprecate.html#Hexstring%20literals
>
> Hence, the grammar has been incompletely updated. As it's not an error to use them now, it should have stated that they are deprecated.
>
> Anyhow, you can always go back in time:
>
> https://docarchives.dlang.io/v2.078.0/spec/lex.html#HexString
Doesn't that go against the idea of -betterC, or will std.conv work with -betterC.
p.s. contrary to what the deprecation notice says, hex strings are very often used in crypto/hashing test cases. Most hash specs have example hash strings to verify implementation code.
|
February 07, 2018 Re: missing HexString documentation | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ralph Doncaster | On Wednesday, 7 February 2018 at 15:54:05 UTC, Ralph Doncaster wrote:
> Doesn't that go against the idea of -betterC, or will std.conv work with -betterC.
>
> p.s. contrary to what the deprecation notice says, hex strings are very often used in crypto/hashing test cases. Most hash specs have example hash strings to verify implementation code.
As expected,
auto data = cast(ubyte[]) x"deadbeef";
works with -betterC, but
auto data = cast(ubyte[]) hexString!"deadbeef";
does not.
|
February 07, 2018 Re: missing HexString documentation | ||||
---|---|---|---|---|
| ||||
Posted in reply to Seb | On 2/7/18 10:41 AM, Seb wrote:
> On Wednesday, 7 February 2018 at 15:25:05 UTC, Steven Schveighoffer wrote:
>> On 2/7/18 9:59 AM, Ralph Doncaster wrote:
>>> It is mentioned in the literals section, but not documented:
>>> https://dlang.org/spec/lex.html#string_literals
>>>
>>> From reading forum posts I managed to figure out that HexStrings are prefixed with an x. i.e. x"deadbeef"
>>>
>>
>> Good catch! Even the grammar says nothing about what it is, except it has HexString as a possible literal.
>>
>> Can you file an issue? https://issues.dlang.org
>>
>
> They are deprecated:
>
> https://dlang.org/changelog/pending.html#hexstrings
> https://dlang.org/deprecate.html#Hexstring%20literals
Wow, that's... a little superfluous.
So we support this:
"\xde\xad\xbe\xef"
but not this?
x"deadbeef"
Seems like the same code you would need to parse the first is reusable for the second, no? I don't see why this deprecation was necessary, and now we have more library/template baggage.
-Steve
|
February 07, 2018 Re: missing HexString documentation | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ralph Doncaster | On Wednesday, 7 February 2018 at 16:03:17 UTC, Ralph Doncaster wrote:
> As expected,
> auto data = cast(ubyte[]) x"deadbeef";
> works with -betterC, but
> auto data = cast(ubyte[]) hexString!"deadbeef";
> does not.
That's just because -betterC is buggy and extremely incomplete (this is why I'm so annoyed that it is getting advertised, it is nowhere near ready for use). there's no reason why it shouldn't work once those bugs get fixed.
|
February 07, 2018 Re: missing HexString documentation | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | On Wednesday, 7 February 2018 at 16:03:36 UTC, Steven Schveighoffer wrote: > On 2/7/18 10:41 AM, Seb wrote: >> On Wednesday, 7 February 2018 at 15:25:05 UTC, Steven Schveighoffer wrote: >>> On 2/7/18 9:59 AM, Ralph Doncaster wrote: >>>> It is mentioned in the literals section, but not documented: >>>> https://dlang.org/spec/lex.html#string_literals >>>> >>>> From reading forum posts I managed to figure out that HexStrings are prefixed with an x. i.e. x"deadbeef" >>>> >>> >>> Good catch! Even the grammar says nothing about what it is, except it has HexString as a possible literal. >>> >>> Can you file an issue? https://issues.dlang.org >>> >> >> They are deprecated: >> >> https://dlang.org/changelog/pending.html#hexstrings >> https://dlang.org/deprecate.html#Hexstring%20literals > > Wow, that's... a little superfluous. > > So we support this: > > "\xde\xad\xbe\xef" > > but not this? > > x"deadbeef" > > Seems like the same code you would need to parse the first is reusable for the second, no? I don't see why this deprecation was necessary, and now we have more library/template baggage. > > -Steve For the same reason why octal literals have been deprecated years ago: https://dlang.org/deprecate.html#Octal%20literals The library solution works as well and it's one of the features that are rarely used and add up to the steep learning curve. |
February 07, 2018 Re: missing HexString documentation | ||||
---|---|---|---|---|
| ||||
Posted in reply to Seb | On Wednesday, 7 February 2018 at 16:51:02 UTC, Seb wrote: > For the same reason why octal literals have been deprecated years ago: > > https://dlang.org/deprecate.html#Octal%20literals > > The library solution works as well and it's one of the features that are rarely used and add up to the steep learning curve. That's actually not the reason given. Octal literals had the stupid leading 0. We should have just made it 0o instead. The library solution does not work just as well, since it doesn't work at all in some places. Behold: http://dpldocs.info/experimental-docs/source/core.sys.posix.fcntl.d.html#L123 version (X86) { enum O_CREAT = 0x40; // octal 0100 enum O_EXCL = 0x80; // octal 0200 enum O_NOCTTY = 0x100; // octal 0400 enum O_TRUNC = 0x200; // octal 01000 That's from druntime. The comments being there indicate the hex is not obvious in this context; the octal would be more illustrative. But the lack of use of std.conv shows it wasn't applicable where the literal was (since this is druntime, phobos isn't available). The octal library solution is brilliant. The genius who wrote that code is clearly god-like and we should all fall to our knees and worship his superior intellect. That pattern DOES have uses. But for octal? It was a mistake. We should have just made it 0o. Similarly, I think the mistake of hex strings is that they are typed char[] instead of ubyte[]. Otherwise... they work ok. And when learning, you don't need to know every bit. You'd just ignore it unless you hit upon the niche where it matters. (that's the way I learned basically all of D. my early D code is virtually identical to my C code, a bit later, similar to old style Java code. only after being in it for a while did i go nuts mastering the language.) |
February 07, 2018 Re: missing HexString documentation | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adam D. Ruppe | On Wednesday, 7 February 2018 at 17:01:54 UTC, Adam D. Ruppe wrote: > The octal library solution is brilliant. The genius who wrote that code is clearly god-like and we should all fall to our knees and worship his superior intellect. That pattern DOES have uses. Octal predates GitHub, hexString is new: https://github.com/dlang/phobos/pull/3133 |
Copyright © 1999-2021 by the D Language Foundation