MathGroup Archive 2007

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

Search the Archive

Re: Clean-up code for packages

  • To: mathgroup at smc.vnet.net
  • Subject: [mg74955] Re: Clean-up code for packages
  • From: Albert <awnl at arcor.net>
  • Date: Thu, 12 Apr 2007 04:56:38 -0400 (EDT)
  • References: <evht7d$2lv$1@smc.vnet.net>

Hi,

> Is there a way for packages to set up some clean-up code that is
> executed before Quit[]? (e.g. delete temporary files that may have
> been created by package functions)

I don't know if there is a better way to do this than to manipulate 
$Epilog...

> I found $Epilog, but I cannot figure out how to prepend commands to it
> if it is already defined. E.g. the default value of $Epilog is
> $Epilog := <<end`
> and I'd like to modify it to be
> $Epilog := (someCommand[];<<end`)
> without knowing the its initial value.
> 
> Is there a way to do this safely? Or is there any other way to run the
> clean-up code when the session is terminated?

... but this is one way to alter $Epilog, I hope it will be "save 
enough" for your needs. You need to look up the OwnValues directly to 
get ahold of the unevaluated code and then take some care to not 
evaluate it too early:

SetDelayed @@@ Cases[
   OwnValues[$Epilog],
   HoldPattern[RuleDelayed[Verbatim[HoldPattern][$Epilog], origcode_]] :>
     Hold[$Epilog, CompoundExpression[myCommand[], origcode]]
]

(* test it: *)
myCommand[] := Print["Hello!"];
Quit[]


Of course there are other ways to extract the origcode, when testing you 
might look at OwnValues[$Epilog] before and after evaluating the above 
expression...

hth,

albert


  • Prev by Date: Re: Marking pivot elements in a matrix?
  • Next by Date: Re: numerical inversion of laplace transform
  • Previous by thread: Re: Clean-up code for packages
  • Next by thread: Re: Clean-up code for packages