Skip to main content
deleted 18 characters in body
Source Link
Mr.Wizard
  • 273.1k
  • 34
  • 595
  • 1.4k

Modified code from the help file on $Pre:

$PreRead =.
    SetAttributes[saveinputs, HoldAll];
    inputs = {};
    saveinputs[new_] := (inputs = {inputs, HoldForm[new]}; new);
    $PreRead$PreRead =.

SetAttributes[saveinputs, HoldAll];
inputs = {};
saveinputs[new_] := (inputs = {inputs, HoldForm[new]}; new);
$PreRead = saveinputs;

Evaluating:

<>

then

Flatten[inputs]

{<>,8.,RowBox[{Flatten,[,inputs,]}]}

If you look at the Cell Expression for the 8. it is actually a TagBox

TagBox["8.`", HoldForm]

Why does a syntax error cause this?

Example where this causes a problem in code:

$PreRead =.
  SetAttributes[saveinputs, HoldAll];
  inputs = {};
  saveinputs[new_] := (inputs = {inputs, HoldForm[new]};
    If[Unevaluated[new],
     new,
     new);
$PreRead$PreRead =.

SetAttributes[saveinputs, HoldAll];
inputs = {};
saveinputs[new_] := (inputs = {inputs, HoldForm[new]};
  If[Unevaluated[new],
   new,
   new);
$PreRead = saveinputs;

When evaluating pretty much anything you get:

ToExpression::esntx: Could not parse 8.` as Mathematica input.

If the test clause of the if statement in the above code does not depend on new then it runs fine.

$PreRead =.
  SetAttributes[saveinputs, HoldAll];
  inputs = {};
  saveinputs[new_] := (inputs = {inputs, HoldForm[new]};
    If[True,
     new,
     new);
$PreRead$PreRead =.

SetAttributes[saveinputs, HoldAll];
inputs = {};
saveinputs[new_] := (inputs = {inputs, HoldForm[new]};
  If[True,
   new,
   new);
$PreRead = saveinputs;

The above works fine.

How am I changing new in the test clause to cause this to fail?

Modified code from the help file on $Pre:

$PreRead =.
    SetAttributes[saveinputs, HoldAll];
    inputs = {};
    saveinputs[new_] := (inputs = {inputs, HoldForm[new]}; new);
    $PreRead = saveinputs;

Evaluating:

<>

then

Flatten[inputs]

{<>,8.,RowBox[{Flatten,[,inputs,]}]}

If you look at the Cell Expression for the 8. it is actually a TagBox

TagBox["8.`", HoldForm]

Why does a syntax error cause this?

Example where this causes a problem in code:

$PreRead =.
  SetAttributes[saveinputs, HoldAll];
  inputs = {};
  saveinputs[new_] := (inputs = {inputs, HoldForm[new]};
    If[Unevaluated[new],
     new,
     new);
$PreRead = saveinputs;

When evaluating pretty much anything you get:

ToExpression::esntx: Could not parse 8.` as Mathematica input.

If the test clause of the if statement in the above code does not depend on new then it runs fine.

$PreRead =.
  SetAttributes[saveinputs, HoldAll];
  inputs = {};
  saveinputs[new_] := (inputs = {inputs, HoldForm[new]};
    If[True,
     new,
     new);
$PreRead = saveinputs;

The above works fine.

How am I changing new in the test clause to cause this to fail?

Modified code from the help file on $Pre:

$PreRead =.

SetAttributes[saveinputs, HoldAll];
inputs = {};
saveinputs[new_] := (inputs = {inputs, HoldForm[new]}; new);
$PreRead = saveinputs;

Evaluating:

<>

then

Flatten[inputs]

{<>,8.,RowBox[{Flatten,[,inputs,]}]}

If you look at the Cell Expression for the 8. it is actually a TagBox

TagBox["8.`", HoldForm]

Why does a syntax error cause this?

Example where this causes a problem in code:

$PreRead =.

SetAttributes[saveinputs, HoldAll];
inputs = {};
saveinputs[new_] := (inputs = {inputs, HoldForm[new]};
  If[Unevaluated[new],
   new,
   new);
$PreRead = saveinputs;

When evaluating pretty much anything you get:

ToExpression::esntx: Could not parse 8.` as Mathematica input.

If the test clause of the if statement in the above code does not depend on new then it runs fine.

$PreRead =.

SetAttributes[saveinputs, HoldAll];
inputs = {};
saveinputs[new_] := (inputs = {inputs, HoldForm[new]};
  If[True,
   new,
   new);
$PreRead = saveinputs;

The above works fine.

How am I changing new in the test clause to cause this to fail?

Source Link
Davorak
  • 407
  • 4
  • 7

Why do syntax errors make a 8.` run through $PreRead in a TagBox?

Modified code from the help file on $Pre:

$PreRead =.
    SetAttributes[saveinputs, HoldAll];
    inputs = {};
    saveinputs[new_] := (inputs = {inputs, HoldForm[new]}; new);
    $PreRead = saveinputs;

Evaluating:

<>

then

Flatten[inputs]

{<>,8.,RowBox[{Flatten,[,inputs,]}]}

If you look at the Cell Expression for the 8. it is actually a TagBox

TagBox["8.`", HoldForm]

Why does a syntax error cause this?

Example where this causes a problem in code:

$PreRead =.
  SetAttributes[saveinputs, HoldAll];
  inputs = {};
  saveinputs[new_] := (inputs = {inputs, HoldForm[new]};
    If[Unevaluated[new],
     new,
     new);
$PreRead = saveinputs;

When evaluating pretty much anything you get:

ToExpression::esntx: Could not parse 8.` as Mathematica input.

If the test clause of the if statement in the above code does not depend on new then it runs fine.

$PreRead =.
  SetAttributes[saveinputs, HoldAll];
  inputs = {};
  saveinputs[new_] := (inputs = {inputs, HoldForm[new]};
    If[True,
     new,
     new);
$PreRead = saveinputs;

The above works fine.

How am I changing new in the test clause to cause this to fail?