Bug introduced in 8 or earlier and persisting through 12.0
CASE:3910218
When you input
{ 1 , 2 } (*spaces intended, retype them if you want to copy this*)
The underlying structure (Ctrl+Shift+E) is:
boxes = RowBox[{"{", " ", RowBox[{"1", " ", ",", " ", "2"}], " ", "}"}]
You can evaluate input cell or do something like
ToExpression[boxes]
{1,2}
and it works nicely, however:
MakeExpression[boxes, StandardForm]
Syntax::sntxf : "{ " cannot be followed by "1 , 2 }".
ErrorBox[RowBox[{"{", " ", ErrorBox[RowBox[{"1", " ", ",", " ", "2"}]], " ", "}"}]]
Questions
Is this a bug or have I missed something?
What would be the best workaround?
MakeExpression[boxes /. " " -> Nothing, StandardForm]
looks fineWhat does the FrontEnd do before sending boxes for evaluation, LinkSnooper shows that
" "
are not present when the content is sent:EnterExpressionPacket[ MakeExpression[ BoxData[RowBox[{"{", RowBox[{"1", ",", "2"}], "}"}]] , StandardForm ] ]
Trace[ToExpression[boxes], TraceInternal -> True]
? It callsStripBoxes
as the first step which removes the redundant spaces. Then the output is sent toMakeExpression
which returnsErrorBox[ErrorBox[RowBox[{"1", ",", "2"}]]]
as intermediate result. But I don't understand why this intermediate result is ignored and the expected output is returned nevertheless. $\endgroup$StripBoxes
: "When boxes are sent by the front end to the kernel for evaluation, the front end strips the boxes using a more extensive process that may depend upon active stylesheets and front end option settings. However, when working with functions that directly serialize notebook constructs such asNotebookRead
, no stripping will occur." $\endgroup$MakeExpression[StripBoxes@boxes, StandardForm]
seems to work (but note the citation in the previous comment: "... the front end strips the boxes using a more extensive process ..."). $\endgroup$ToExpression
does the same thing as what is done at Shift+Return event. p.s. I thinkStripBoxes
is worth an answer, $\endgroup$StripBoxes
is introduced in version 6.0 (actuallyStripBoxes
was present already in version 3.0!). I'm pretty sure it isn't a bug, just incomplete documentation on the difference betweenToExpression
andMakeExpression
. $\endgroup$