Hacker News new | past | comments | ask | show | jobs | submit login

> Like, I challenge you to provide a working version of ohce in Python (2 or 3: your choice).

Not a full implementation, but wouldn't this approach actually work (note, doesn't work for python2):

    $ python3
    Python 3.2.3 (default, Feb 20 2013, 14:44:27) 
    [GCC 4.7.2] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> "abc"[::-1]
    'cba'
    >>> "øæåにほ言"[::-1]
    '言ほにåæø'
    [edit: with accents]:
    >>> "eẽêëèøæåにほ言"[::-1]
    '言ほにåæøèëêẽe'

    [edit2: formatting, indentation]
There might very well be problems with this, but I'm not aware of any?

[edit4: This is indeed broken for the ligature (baffle) case in python3. I'm not entirely sure that is an entirely fair test (but it is very interesting). I would argue that the ligature should probably be a replacement done for display/print, not in a text file. Just like the reverse of "æ" isn't a reverse composition of "e" and "a" (even if "æ" might be seen as a compositon of "a" and "e".

I'm not sure how it deals with changing direction (left-to-right, right-to-left) -- comments welcome.]

[edit3, sorry for the many edits]

To be clear, I do not wish to "pick on c++", nor do I think the example is trivial. I do think it probably should be trivial -- it is something that should be supported in a canonical way by a standard library/implementation.

Working with graphemes is a very fundamental part of working with text -- the fact that half(?) of developers have been able to hide behind ascii isn't a good excuse for not fixing it. How would one implement an editor if you can't access graphemes in a reasonable way?

And more importantly, how would you test for palindromes? ;-)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: