2
$\begingroup$

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?

$\endgroup$
  • $\begingroup$ You may be loading an init.m which would execute first? $\endgroup$ – Ymareth Dec 4 '14 at 9:00
  • $\begingroup$ 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? $\endgroup$ – Albert Retey Dec 4 '14 at 10:05
  • $\begingroup$ 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. $\endgroup$ – dubroua Dec 4 '14 at 11:28
  • $\begingroup$ 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? $\endgroup$ – Albert Retey Dec 4 '14 at 14:15
  • $\begingroup$ 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 $\endgroup$ – dubroua Dec 4 '14 at 19:22
2
$\begingroup$

I looked in the code of new JLink package of the Mathematica 10.0.1: it has 2 more evaluations under the hood per each evaluation and discards the answer from the Kernel. One is a preEval method that sets the evaluation format and another is postEval.

MathSessionTextPane.this.ml.evaluate("{JLink`Private`cfv, JLink`Private`sopts, JLink`Private`ddf} = {FormatValues[Continuation], Options[\"stdout\"], $DisplayFunction} ; Format[Continuation[_], OutputForm] = \"\" ; SetOptions[\"stdout\", FormatType -> OutputForm, CharacterEncoding -> \"Unicode\", PageWidth -> " + paneWidthInChars + "] ; " + "$DisplayFunction = " + df + ";");


MathSessionTextPane.this.ml.evaluate("FormatValues[Continuation] = JLink`Private`cfv ; SetOptions[\"stdout\", JLink`Private`sopts] ; $DisplayFunction = JLink`Private`ddf ;");
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.