Live data from Hacker News

Why can't you reverse a string with a flag emoji?

davidamos.dev

91–100 of 247 posts

Re: Why can't you reverse a string with a flag emoji?

#92

Earlier quoted context omitted.

In my browser (Firefox on Windows), the thing between the quotes in the first block of code looks like a picture of the US flag cropped to a circle, not like the characters "us".

Ah I see, I just opened it in firefox. It looks like some JS library is not getting loaded in Edge. The author was talking about "us", "so", etc. looking like one character and I thought I was going crazy, lol.

I don't think that's about a JS library. Firefox bundles an emoji font that supports some things -- such as the flags -- that aren't supported by Segoe UI Emoji on Windows, so it has additional coverage for such character sequences.

Re: Why can't you reverse a string with a flag emoji?

#93
post #36

Earlier quoted context omitted.

UTF-8 reverse string has been a thing for a long time in most/all programming languages. It may not work perfectly in 100% of the cases, but that doesn't mean reversing a string is no longer possible.

> It may not work perfectly in 100% of the cases, but that doesn't mean reversing a string is no longer possible. I don't understand why in maths finding one single counter-example is enough to disprove a theorem yet in programming people seem to be happy with 99.x % of success rate. To me, "It may not work perfectly in 100% of the cases" exactly means "no longer possible" as "possible" used to imply that it would wo…

It is very useful in engineering to do things that are mathematically impossible, by simply ignoring or rejecting the last 1%.

Sometimes that's unacceptable, because you really do care about 100% of cases. When it isn't, you get really cool "impossible" tools out of it :)

Re: Why can't you reverse a string with a flag emoji?

#94
post #74

This misses the real problem with flag emoji in that they are composed of codepoints that can be in any order. With other emoji you get a base codepoint with potential combining characters. Using a table of combining character ranges you can skip over them and isolate the logical glyph sequences. You don't need surrounding context to parse them out like flags need.

I think that somewhere in this answer lies a reason why Windows still doesn't support flag emoji. I don't count Microsoft Edge as "Windows" in this case, but as Chromium. Windows doesn't support flag emoji in its native text boxes, but it does support even colorized emoji. But then again, flags seem to be not only Unicode-hard but post-Unicode-hard.

> But then again, flags seem to be not only Unicode-hard but post-Unicode-hard.

Flags are not that hard, they're a very specific block combining in very predictable way. They're little more than ligatures. Family emoji are much harder.

And this is not "post-Unicode" in any way.

Re: Why can't you reverse a string with a flag emoji?

#95
post #55

Earlier quoted context omitted.

"It may not work perfectly in 100% of the cases, but that doesn't mean reversing a string is no longer possible." It depends on your point of view. From a strict point of view, it does exactly mean it is no longer possible. By contrast, we all 100% knew what reversing an ASCII string meant, with no ambiguity. It also depends on the version of Unicode you are using, and oh by the way, unicode strings do not come annot…

> By contrast, we all 100% knew what reversing an ASCII string meant, with no ambiguity. Not if the ASCII string employed the backspace control character to accomplish what is today done with Unicode combining characters. Or, in fact, if it employed any other kind of control sequence.

I always thought it was interesting that ASCII is transparently just a bunch of control codes for a typewriter (where "strike an 'a'" is a mechanical instruction no different from "reset the carriage position"), but when we wanted to represent symbolic data we copied it and included all of the nonsensical mechanical instructions.

Re: Why can't you reverse a string with a flag emoji?

#96

If you think the Unicode flag emoji take a lot of bytes, then consider the family emoji! ( https://unicode.org/emoji/charts/full-emoji-list.html#family ) I'm in the process of designing a scripting language and implementing it in C++. I plan to put together a YouTube series about it. (Doesn't everyone want to see Bison and Flex mixed with proper unit tests and C++20 code?) Due to my future intended use case, I needed…

It always feels like the most amount of work goes to the least used emoji. So many revisions and additions to the family emoji and yet it’s one of the ones I don’t recall anyone ever using. I think the trap Unicode got in to is technically they can have infinite emoji so they just don’t ever have a way to say no to new proposals.

They do say no though. Frequently too.

The problem with Unicode is simply that it’s trying to solve a very hard problem.

Re: Why can't you reverse a string with a flag emoji?

#97
post #92

Earlier quoted context omitted.

Ah I see, I just opened it in firefox. It looks like some JS library is not getting loaded in Edge. The author was talking about "us", "so", etc. looking like one character and I thought I was going crazy, lol.

I don't think that's about a JS library. Firefox bundles an emoji font that supports some things -- such as the flags -- that aren't supported by Segoe UI Emoji on Windows, so it has additional coverage for such character sequences.

That makes sense. I saw a failure to load a JS module in the console and assumed that was part of the problem.

Re: Why can't you reverse a string with a flag emoji?

#98
Unfortunately the HN text input won't let me do this, but a funny starter for the article would have been this:

'(Spanish flag)'[::-1]

basically ''.join([chr(127466), chr(127480)]) vs. ''.join([chr(127466), chr(127480)])[::-1]

I'll add this to my collection of party tricks and show myself out.

Cool article!

Re: Why can't you reverse a string with a flag emoji?

#99
post #11

Earlier 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…

You can even demonstrate a similar concept with English and Latin characters. There is no single thing called a "grapheme" linguistically. There are actually two different types of graphemes. The character sequence "sh" in English is a single referential grapheme but two analogical graphemes. Depending on what the specification means, "short" could be reversed as either "trosh" or "trohs". That's without getting into transliteration. The word for Cherokee in the Cherokee language is "Tsalagi" but the "ts" is a Latin transliteration of a single Cherokee character. Should we count that as one grapheme or two?

Of course, if an interviewer is really asking you how to do this, they're probably either 1) working in bioinformatics, in which case there are exactly four ASCII characters they really care about and the problem is well-defined, or 2) it's implementing something like rev | cut -d '-' -f1 | rev to get rid of the last field and it doesn't matter how you implement "rev" just so long as it works exactly the same in reverse and you can always recover the original string.

Re: Why can't you reverse a string with a flag emoji?

#100

But 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?

Galaxy brain image reversal: completely redraw it from scratch, with a viewpoint 180º from the original.

New computer vision challenge
Post reply on HN