4

I am introducing the mathematica Security (MSP module) to our system. The Document suggests use MSPToExpression as followed:

Needs["MSP`"]

SetSecurity[];

$$var = "5+7";

MSPToExpression[ $$var] (*the output is 12*)

But when I tried to adapt this function to $PrePrint with scripts:

$PrePrint = With[{$$var = ToString[#, InputForm]}, MSPToExpression[$$var]] &;
(*or*)

$PrePrint = With[{expr = #}, MSPToExpression[expr]] &;
(*or*)

$PrePrint = With[{$$var = #}, MSPToExpression[$$var]] &;

Input: 5+7

there's same error says: enter image description here

It can't recognize $$var as symbol, can anyone help me on this? Many thanks! :)

Kuba
  • 136,707
  • 13
  • 279
  • 740
Michael
  • 491
  • 2
  • 9

1 Answers1

4

I suppose this is what you need.

So the first thing is to use Module since With injects values into held expressions.

Moreover PrePrint is probably to late to catch "5+7". So I'd go with $Pre:

$Pre = Function[expr, 
  Module[
        {expr$ = ToString[Unevaluated[expr], InputForm]},
         MSPToExpression[expr$]
  ],
  HoldAllComplete
]
Kuba
  • 136,707
  • 13
  • 279
  • 740