Re: How to print/display symbolic expressions from inside a Module
- To: mathgroup at smc.vnet.net
- Subject: [mg104226] Re: How to print/display symbolic expressions from inside a Module
- From: Norbert Marxer <marxer at mec.li>
- Date: Sat, 24 Oct 2009 02:40:09 -0400 (EDT)
- References: <hbr599$rh2$1@smc.vnet.net>
On Oct 23, 4:43 am, "Nasser M. Abbasi" <n... at 12000.org> wrote:
> Hello;
>
> I use Print[] allot while debugging, and trace how the expression evolve
> etc... while it is still symbolic, before I plug in numerical values.
>
> But when I have a Module, and use Print[] on expression which involves lo=
cal
> variables, they all print with a $ sign ofcourse. This makes it hard t=
o
> read the expressions.
>
> foo[] := Module[{x, y,expr},
> expr= x^2 + y;
> Print[" expression now is ",
> ToString[expr,FormatType->Traditi=
onalForm]]
> ]
> foo[]
> expression now is x$589^2+y$589
>
> A standard way to solve this is to pass the symbols themselves as in
>
> foo[x_, y_] := Module[{expr}, expr = x^2 + y;
> Print[" expression now is =
",
> ToString[expr,Form=
atType -> TraditionalForm]]
> ]
>
> Remove[x, y]
> foo[x, y]
> expression now is x^2+y
>
> But the problem is that I am calling foo[] itself from inside yet another
> Module, and I also can't have global variables at all. So, everything =
is
> wrapped inside a Module, and every symbol much have a scope inside, nothi=
ng
> global.
>
> So, the only option I see (which I am going to try next, do not know if i=
t
> will work) is to make a pattern which strips these $nnn from the symbols =
for
> display purposes?
>
> Or Am I missing some other simple solution to this common problem?
>
> Thanks,
> --Nasser
Hello
Use Block (instead of Module).
Best Regards
Norbert Marxer