WolframLanguageForJupyter
WolframLanguageForJupyter copied to clipboard
Provisionally implement standard hooks in the evaluation loop
For example:
-
$PreRead
-
$SyntaxHandler
-
$Pre
-
$Post
-
$PrePrint
This is being developed in #46.
Also see some initial discussion in #45.
$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
- first question is, how should $PreRead behave, from those examples from Mathematica:
I'd say it is at least not clear. (not called by ToExpression / called / ?12.?
- 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
, ifToExpression
uses it it is fine, otherwise it should be added applied to thecode
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
];
I agree with having WolframLanguageForJupyter
apply $PreRead
(if it is set) to the input, and letting any sub-ToExpression
s 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 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.
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
#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.
A general request for comments on #46 is at #48.
$PreRead
$Pre
$Post
$PrePrint
This first set of hooks should now be represented in master
.