3

I am evaluating expression by using KernelLink.

But the kernel will be suspended endless when meets a invalid escape character. a\abc, \[badEscape] for example.

So I have to filter all the invalid escape characters programmingly.

Is there a way to get all valid escape characters in Mathematica? \[Beta],\[Alpha] and so forth.

This is possibly caused by not all packets are read off properly

I will show the Mathematica code bellowd that you could test easily.

I'm using EnterTextPacket function(which communicates through WSTP) to talk with KernelLink. You could find refercence here

The first case evaluates 10!, and works well

link = LinkLaunch[First[$CommandLine] <> " -wstp"]
LinkRead[link]
LinkWrite[link, EnterTextPacket["10!"]]
LinkRead[link]
LinkRead[link]
LinkRead[link](*the last package*)
LinkClose[link]

works well

we could see the last LinkRead[link] returned In[2]:= indicates all packages read off.

The next case evaluates \[BadEscape] causes packages returned with endless. LinkRead[link] returned Syntax Err continuously.

link = LinkLaunch[First[$CommandLine] <> " -wstp"]
LinkRead[link]
LinkWrite[link, EnterTextPacket["\[BadEscape]"]]
LinkRead[link]
LinkRead[link]
LinkRead[link]
....
(*endless*)

enter image description here enter image description here

So I think this must be the problem. Does this make sense ?

Michael
  • 491
  • 2
  • 9
  • Do you mean J/Link? Can you give a specific example that causes the kernel to hang? It shouldn't hang. Maybe you are just not reading off all the packets (error messages) from the link ... – Szabolcs Jan 18 '16 at 09:09
  • The reason why I wouldn't mark it as duplicate is that very likely the cause of the problem is not the invalid named character. Instead the link might be blocking because not all packets are read off properly. Thus the solution is not to filter these named characters. – Szabolcs Jan 18 '16 at 11:13
  • @Szabolcs thanks for reply. Yes, it's J/Link, called by java. I will give you the specified code tommorow since I am out off office. – Michael Jan 18 '16 at 13:11
  • I am not familiar with J/Link itself, but the sequence of calls should be similar to the C interface of MathLink ... so maybe I can comment – Szabolcs Jan 18 '16 at 13:19
  • @Szabolcs I edited the question with code. Please take a look, thanks – Michael Jan 19 '16 at 08:28
  • Very strange. I don't know what is going on. Other syntax errors that appear at position 0, such as from *2, do not cause an infinite number of packets. I wonder if this is a bug. Minor note: it should be "\\[BadEscape]", with a double "\\" that encodes a single \ in a string. But that's not the cause of the problem. Just about any input starting with a backslash triggers this. – Szabolcs Jan 19 '16 at 10:01
  • @Szabolcs No idea if it's a bug, so just leave this to the expert or the developer. I am going to filter escapes programmingly. – Michael Jan 19 '16 at 11:46
  • What are you programming exactly? EvaluatePacket with ToExpression and maybe SyntaxQ might be a good workaround ... – Szabolcs Jan 19 '16 at 11:48
  • Could you please report this problem to Wolfram and let us know what they said? I am curious. Looks like a bug. – Szabolcs Jan 25 '16 at 13:52
  • @Szabolcs Could you please provide a way that I can get touch with Wolfram ? Or do you mean http://community.wolfram.com/ ? – Michael Jan 27 '16 at 06:36
  • @Michael The contact options are shown here: http://www.wolfram.com/support/contact/?source=nav You can also email support@wolfram.com. – Szabolcs Jan 27 '16 at 08:33
  • This bothers me to no end so I reported it after all. CASE:3523179. – Szabolcs Jan 29 '16 at 16:57
  • @Szabolcs thanks. I was a little busy. could you please message me here when you get the result ? – Michael Feb 01 '16 at 08:03
  • 1
    @Szabolcs Just let you known, Wolfram has confirmed this's a native defect. I just got the feedback email. This will be fixed in next release. – Michael Jul 19 '16 at 02:58

1 Answers1

5

The help documentation has a section called Listing of Named Characters. One way to get to it is to hit the F1 key and then paste the following into the documentation window:

guide/ListingOfNamedCharacters

To generate a list programmatically, code

codes = Table[ToString[
    FromCharacterCode[u],
    InputForm,
    CharacterEncoding -> "PrintableASCII"],
   {u, 0, 65535}];
lnames = Flatten@StringCases[codes, "\\[" ~~ __ ~~ "]" ];

In MMA 10.3, that should generate a list of 1005 long names. It may or may not match the named character list in the documentation.

LouisB
  • 12,528
  • 1
  • 21
  • 31