MathGroup Archive 2008

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

Search the Archive

Re: Function changes in a program

  • To: mathgroup at smc.vnet.net
  • Subject: [mg92290] Re: Function changes in a program
  • From: Albert Retey <awnl at gmx-topmail.de>
  • Date: Sat, 27 Sep 2008 06:47:08 -0400 (EDT)
  • References: <gbfloa$68a$1@smc.vnet.net>

Chris Degnen wrote:
> Hi
> 
> Does anyone have a suggestion on how to
> check for changes in environment function
> variables in a program. I.e. starting with ...
> 
> initial environment
> 
> f[a]=1
> f[b]=2
> 
> 
> later environment
> 
> f[a]=1
> f[b]=99
> f[m]=3
> 
> I'd like to be able to determine that
> f[b] had changed and f[m] was added. 

you just need to check the DownValues of f, like this:

(* create definitions for f *)
f[a] = 1
f[b] = 2

(* save current state for later reference *)
saveenv = DownValues[f]

(* change definitions *)
f[a] = 1
f[b] = 99
f[m] = 3

(* check whether something has changed: *)
DownValues[f] === saveenv

(* poor mans diff *)
Union[Flatten[{
   Complement[DownValues[f], saveenv],
   Complement[saveenv, DownValues[f]]
   }]]

hth,

albert


  • Prev by Date: Re: Help
  • Next by Date: RE: How to do symbolic matrix manipulations
  • Previous by thread: Re: Function changes in a program
  • Next by thread: Solution partial differential equation