[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Challenges of adding octal and hexadecimal escape sequences in strin

From: Mohammad-Reza Nabipoor
Subject: Re: Challenges of adding octal and hexadecimal escape sequences in strings
Date: Sat, 31 Oct 2020 16:34:21 +0330

On Sat, Oct 31, 2020 at 01:36:40PM +0100, Jose E. Marchesi wrote:
> > Hi, Jose!
> >
> > On Fri, Oct 30, 2020 at 05:51:44PM +0100, Jose E. Marchesi wrote:
> >> 
> >> I don't think that is the desired behavior.  If we define Poke strings
> >> as NULL-terminated, it is obvious they are not to contain any NULL
> >> byte.  Now, we can achieve that by two ways:
> >> 
> >> a) By doing what we do now, i.e to ignore any part of the string after a
> >>    NULL character, in case one is inserted, or
> >> 
> >> b) To emit an error whenever a 0 byte is attempted to be stored in a
> >>    string value.
> >> 
> >> Supposing we wanted to switch to b), at the moment the only ways to
> >> create a string value in Poke are:
> >> 
> >> b1) Using a string literal, and
> >> b2) using a cast from uint<8> to string
> >> 
> >> The first case is easy to implement: just emit a compile-time error if a
> >> string literal contains a null character.
> >> 
> >> For the second case we have two choices: either to raise an exception
> >> when `8UB as string' is executed, or to keep the current behavior of
> >> generating an empty string "", but the latter would be an exception to
> >> the rule.
> >> 
> >> That's why I prefer a) to b): it is more orthogonal, and can be
> >> explained by a single rule without needing any exceptions to the rule.
> >> Also, it comes handy to shorten strings :D
> >
> > What about a third way:
> >
> > c) Keep Poke strings as NULL-terminated. Treat using of NULL character in 
> > string
> >    literals as compilation error.
> >
> > The user cannot access data beyond the first NULL character, and having 
> > bytes
> > beyond that character doesn't make any sense.
> Isn't that a subset of b) above?

It's a nice subset of the "b" :D
Just "b1".

I mean if Poke string is a NULL-terminated thing, and user tries to make a
string using a "string literal" (a compile-time thing) we should emit an error.
The other parts like "cast from uint<8> to string" is not important.
Because the user (probably) knows what he/she is doing (and it's a runtime 
But for a "string literal", IMHO the user definitely doesn't know what he/she is
doing! (because he/she cannot access the bytes beyond the first NULL character).

defvar s = "a\0b"; // this should emit an compiler error (not an exception).
                   // this should be considered as meaningless as
                   // "defvar i = + 1 2;"

I think "error" is better than "ignoring" for string literals.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]