MathGroup Archive 2002

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

Search the Archive

Re: Removing the Context

  • To: mathgroup at smc.vnet.net
  • Subject: [mg35690] Re: Removing the Context
  • From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
  • Date: Fri, 26 Jul 2002 04:16:32 -0400 (EDT)
  • Organization: Universitaet Leipzig
  • References: <ahoe71$bsp$1@smc.vnet.net>
  • Reply-to: kuska at informatik.uni-leipzig.de
  • Sender: owner-wri-mathgroup at wolfram.com

Hi,

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

Remove[RemoveContextString]

RemoveContextString[s_String] := RemoveContext[s] = Module[{lst, p,
str},
      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],
        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.

Regards
  Jens




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