# JLink does not preserve the input cell number

I use JLink for connecting to the Mathematica kernel and evaluate some expressions. The In[] prompt is not continuous - it has step 3. I.e. the first expression is In[1] and after the evaluation the next one is In[4]. I obtained this kind of behavior on the rescent Mathematica 10.0.1 for Mac OS X 10.10. Is it a JLink bug?

• You may be loading an init.m which would execute first? Dec 4, 2014 at 9:00
• Actually I would guess that it is probably not even documented what the In prompt should behave like when the Kernel is called via JLink. Can you explain why that is a problem? Assuming it is not recommended to rely on a specific ordering of In statements when programmatically using the Kernel it would seem irrelevant what these are for a JLink program, wouldn't it? Dec 4, 2014 at 10:05
• Say you use the MathSessionPane class from the JLink package and the user sees the In[] prompt while entering and evaluating the expressions. Any two sequential evaluations have In[] index gap. Nothing can prevent user from refering to the previous evaluation and this gap is misleading - it is not clear which if % can use the numbers visible as prompt the prompt. Dec 4, 2014 at 11:28
• OK I see, that is of course somewhat disturbing. I have not realized that one can see this not only as an example but also as a building block. It looks like the Kernel/Mathlink behaviour has changed from version 8 to 9 so that now the numbering is wrong, the numbering for the example works correct for older versions (which it presumably was written for). I have no idea how to solve that, you might want to report it to WRI. What is it that you are trying to build? Dec 4, 2014 at 14:15
• I am trying to build a simple front end for IntellyJ Idea ide without compile time dependency ont JLink.jar. See github.com/dubrousky/Mathematica-REPL Dec 4, 2014 at 19:22

MathSessionTextPane.this.ml.evaluate("{JLinkPrivatecfv, JLinkPrivatesopts, JLinkPrivateddf} = {FormatValues[Continuation], Options[\"stdout\"], $DisplayFunction} ; Format[Continuation[_], OutputForm] = \"\" ; SetOptions[\"stdout\", FormatType -> OutputForm, CharacterEncoding -> \"Unicode\", PageWidth -> " + paneWidthInChars + "] ; " + "$DisplayFunction = " + df + ";");
MathSessionTextPane.this.ml.evaluate("FormatValues[Continuation] = JLinkPrivatecfv ; SetOptions[\"stdout\", JLinkPrivatesopts] ; \$DisplayFunction = JLinkPrivateddf ;");