WolframLanguageForJupyter icon indicating copy to clipboard operation
WolframLanguageForJupyter copied to clipboard

Provisionally implement standard hooks in the evaluation loop

Open cc-wr opened this issue 5 years ago • 9 comments

For example:

  • $PreRead
  • $SyntaxHandler
  • $Pre
  • $Post
  • $PrePrint

cc-wr avatar Jun 11 '19 10:06 cc-wr

This is being developed in #46.

cc-wr avatar Jun 11 '19 10:06 cc-wr

Also see some initial discussion in #45.

cc-wr avatar Jun 11 '19 10:06 cc-wr

$PreRead comment

@cc-wr good catch with the front end origin of the problem. It is not limited to WLfP only, you can reproduce it in Mathematica Kernel.exe as well (if you try to rasterize).

Questions

  1. first question is, how should $PreRead behave, from those examples from Mathematica:

image

I'd say it is at least not clear. (not called by ToExpression / called / ?12.?

  1. If 'sub parsing' should be affected, and it probably should then user needs to anticipate that $PreRead can't just be a function that will be fed with strings. Otoh is feels pretty annoying to not be able to assume that $PreRead will work with strings only in a 'text mode'.

Suggestions

  • ToExpression @ frameAssoc.content.code should respect $PreRead, if ToExpression uses it it is fine, otherwise it should be added applied to the code value.

  • Optionally there could be a $JupyterPreRead applied before, which won't interfere with sub parsing. So at the end there would be:

totalResult = ToExpression[
 (*$PreRead @*) $JupyterPreRead @ loopState["frameAssoc"]["content"]["code"], 
 InputForm, 
 uninteract
];

kubaPod avatar Jun 11 '19 14:06 kubaPod

I agree with having WolframLanguageForJupyter apply $PreRead (if it is set) to the input, and letting any sub-ToExpressions do what they want.

  • Optionally there could be a $JupyterPreRead applied before, which won't interfere with sub parsing. [...]

My personal opinion on this is disagreement: I want to keep the peculiarities of the WolframLanguageForJupyter interface itself to a minimum.

cc-wr avatar Jun 11 '19 21:06 cc-wr

@cc-wr I don't have a strong opinion on WLFJ specific solutions so we are settled then :)

About applying $PreRead, the question was when ToExpression does it automatically. I don't know exactly but from experiments it seems that it does not do it when then input is an input form string. Which means that $PreRead should be added manually in all places where content is converted to the code, as code will always be an input form string.

kubaPod avatar Jun 12 '19 07:06 kubaPod

Currently, $PreRead is applied once, in a manner that I think is sufficient, at this location:

https://github.com/WolframResearch/WolframLanguageForJupyter/blob/b63c459fa3dd6356a0f5a22cd3424668b679937d/WolframLanguageForJupyter/Resources/EvaluationUtilities.wl#L300

cc-wr avatar Jun 12 '19 07:06 cc-wr

#46 should support:

  • $PreRead
  • $Pre
  • $Post
  • $PrePrint

I think this is a good stopping point for that pull request, with further additions to be made in succeeding ones.

cc-wr avatar Jun 13 '19 15:06 cc-wr

A general request for comments on #46 is at #48.

cc-wr avatar Jun 13 '19 16:06 cc-wr

  • $PreRead
  • $Pre
  • $Post
  • $PrePrint

This first set of hooks should now be represented in master.

cc-wr avatar Jun 20 '19 15:06 cc-wr