2

Is there any way to programmatically tell whether a given character is a letter or letter-like form (see this reference page for what I mean)?

One idea I had was to use FrontEnd`UndocumentedTestFEParserPacket, to test whether the syntax parser would split the string (i.e. test whether char <> "a" is split), which seems to work. But I am looking for a more provably correct and less undocumented solution if at all possible.

Another idea was to simply check the reference page for a given character/preprocess the full list given above to build a "database" by hand, but it feels like there could be a more straightforward way, hence this question.

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
Lukas Lang
  • 33,963
  • 1
  • 51
  • 97

2 Answers2

1

Hm. Searching for every command involving Letter with *`*Letter*, I found System`Convert`MLStringDataDump`LetterLikeQ. If s is a String, it applies System`Convert`MLStringDataDump`LetterLikeAuxQ to Characters[s] and wraps it with And@@, so it seems to check if a string is entirely composed of letter like characters. Actually, the whole context System`Convert`MLStringDataDump seems to be interesting for you.

Henrik Schumacher
  • 106,770
  • 7
  • 179
  • 309
  • 1
    Thanks! I should really get into the habit of searching functions like this... I just hope this covers all cases, as the list appears to be mostly hard-coded (or rather the complement is) - but since operators aren't changed to frequently, I don't think I need to worry too much. Anyway, this will definitely be the solution I'll use :) – Lukas Lang Apr 07 '18 at 10:06
  • You're welcome. I hope it works out! – Henrik Schumacher Apr 07 '18 at 10:17
1

Reading the documentation of Symbol, the following should work:

LetterLikeQ[char_] := Module[
  {ret},
  Begin["`llq`"];
  ret = Quiet@Check[Remove@Evaluate@Symbol@char; True, False];
  End[];
  ret
]

Some examples:

LetterLikeQ["a"]
(* True *)

LetterLikeQ["•"]
(* True *)

LetterLikeQ["\[Rule]"]
(* False *)
Lukas Lang
  • 33,963
  • 1
  • 51
  • 97
  • Interesting approach. Should be less hacky with Internal`SymbolNameQ. – Henrik Schumacher Apr 08 '18 at 08:34
  • Good point - then this solution would also be a one-liner (LetterLikeQ=Internal`SymbolNameQ)... But in that case I'd still prefer your solution, since both are undocumented, and yours is clearer in its intention – Lukas Lang Apr 08 '18 at 09:23