Unicode defines grapheme clusters[1] that represent "user-perceived characters" separating a string into those and reversing seems like a pretty good way to go about it.
Why can't you reverse a string with a flag emoji?
61–70 of 247 posts
Re: Why can't you reverse a string with a flag emoji?
#62Re: Why can't you reverse a string with a flag emoji?
#63But you can, and did, reverse a string. It seems you would need more details, such as a request to reverse the meaning or interpretation of the string, which is what the author is getting at. If someone challenges you to reverse an image, what do you do? Do you invert the colors? Mirror horizontally? Mirror vertically? Just reverse the byte order?
There's a specification problem here. I like to say that a "string" isn't a data structure, it's the absence of one. Discussing "strings" is pointless. It follows that comparing programming languages by their "string" handling is likewise pointless. Case in point: a "struct" in languages like C and Rust is literally a specification of how to treat segments of a "string" of contiguous bytes.
Is it a PASCAL string (length byte followed by data) or a C string (arbitrary run of bytes terminated by a null character)?
Re: Why can't you reverse a string with a flag emoji?
#64I definitely thought it'd be something like [I am a Flag] and [The flag ID between 0 and 65535]. And reversing it would be [Flag ID] + [I am a Flag] which would not be a defined "component" and instead rendered as the individual two nonsense characters.
Re: Why can't you reverse a string with a flag emoji?
#65Re: Why can't you reverse a string with a flag emoji?
#66Re: Why can't you reverse a string with a flag emoji?
#67I feel like I'm obligated to share this almost 20 year old Spolsky post that gave me my understanding of characters. https://www.joelonsoftware.com/2003/10/08/the-absolute-minim...
In that same vein, here's my introduction to Unicode about 10 years ago from Tom Scott. https://www.youtube.com/watch?v=MijmeoH9LT4
Re: Why can't you reverse a string with a flag emoji?
#68Interestingly, on my phone the so-called flag is not a flag at all, but "US" in outline. So python behaves as expected: the 2 character string, when reversed, becomes "SU". Similar stuff happens with the other "flag" strings. I'm sure emojis in my phone are outdated. I'm not sure how that affects whether I see a flag or letters.
Re: Why can't you reverse a string with a flag emoji?
#69I feel like I'm obligated to share this almost 20 year old Spolsky post that gave me my understanding of characters. https://www.joelonsoftware.com/2003/10/08/the-absolute-minim...
In that same vein, here's my introduction to Unicode about 10 years ago from Tom Scott. https://www.youtube.com/watch?v=MijmeoH9LT4
Re: Why can't you reverse a string with a flag emoji?
#70Earlier quoted context omitted.
Reversing a string is still meaningful. Take a step back outside the implementation and imagine handing a Unicode string to a human. They could without any knowledge look at the characters they see and produce the correct string reversal. There is a solution to this which is to compute the list of grapheme clusters, and reverse that. https://unicode.org/reports/tr29/
> imagine handing a Unicode string to a human. They could without any knowledge look at the characters they see and produce the correct string reversal. I really highly doubt it. How do you reverse this?: مرحبًا ، هذه سلسلة. Can you do it without any knowledge about whether what looks like one character is actually a special case joiner between two adjacent codepoints that only happens in one direction? Can you do it…
Are you referring to a grouping not covered by the definition of grapheme clusters (which I am only passingly familiar with)? If so, then I don't think it's any more non-meaningful to reverse it than to reverse an English string. The result is gibberish to humans either way - it sounds more like you're saying that there is no universally "meaningful to humans" way to reverse some text in potentially any language, which is true regardless of what encoding or written language you're using. I was thinking of it more from the programmer side - i.e. that Unicode provides ways to reverse strings that are more "meaningful" (as opposed to arbitrary) than e.g. just reversing code points.