Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2002

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Removing the Context

  • To: mathgroup at
  • Subject: [mg35690] Re: Removing the Context
  • From: Jens-Peer Kuska <kuska at>
  • Date: Fri, 26 Jul 2002 04:16:32 -0400 (EDT)
  • Organization: Universitaet Leipzig
  • References: <ahoe71$bsp$>
  • Reply-to: kuska at
  • Sender: owner-wri-mathgroup at


at first we need a function that strip the context and hinder
the creation of private sumbols in the global context


RemoveContextString[s_String] := RemoveContext[s] = Module[{lst, p,
      lst = Characters[s];
      p = Position[lst, "`"];
      If[p === {}, Return[ToExpression[s]]];
      p = Last[p];
      str = StringJoin @@ Drop[lst, p[[1]]];
      If[MemberQ[Names["System`*"], str],
        Print[str]; ToExpression[str],

and now

PrettyTrace[trexp_]:=trexp /.s_Symbol :> HoldForm @@
{RemoveContextString[ToString[s]]} /. 
  HoldForm[s_Symbol] :> s

PrettyTrace[Trace[TreeFind[t, 3]] ]

will do what you want.


Johannes Ludsteck wrote:
> Dear MathGroup Members,
> Tracing functions from Packages generates very long
> and confusing output, since long context names are
> printed. To give a short example, consider the following
> command sequence:
> DiscreteMath`Tree`
> t=MakeTree[Range[5]]
> Trace[TreeFind[t,3]]
> generates very long output. A simple strategy to strip
> it would be to use Trace[command, form] which only reports
> expressions matching form.
> But this does not alleviate the problem that package
> variable names are very long, since all package symbols
> have a long context. For example
> the private package variables 'm' and 'found' are printed as
> DiscreteMath`Tree`Private`m      and
> DiscreteMath`Tree`Private`found
> This makes Trace output almost unreadable.
> Can anyone suggest a simple idea how to remove the long
> context names in Trace output?
> I defined a function which cuts the context from
> symbols, but this seems awkward an application of
> the function to the output is not trivial.
> Best regards,
>         Johannes Ludsteck

  • Prev by Date: Mathematica function writing for data analysis at Gould Academy
  • Next by Date: RE: Re: Substitution!!!
  • Previous by thread: Removing the Context
  • Next by thread: Re: Removing the Context