Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2008

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

Search the Archive

Re: Function changes in a program [CORRECTION]

  • To: mathgroup at smc.vnet.net
  • Subject: [mg92282] Re: [mg92262] Function changes in a program [CORRECTION]
  • From: Bob Hanlon <hanlonr at cox.net>
  • Date: Fri, 26 Sep 2008 06:24:51 -0400 (EDT)
  • Reply-to: hanlonr at cox.net

It is more efficient to use Union rather than Join in the definition of stateChanges

stateChanges[s1_List, 
  s2_List] := {Cases[
   Union[s1, 
     s2] //.
    {s___, HoldPattern[f_] :> f1_, m___, 
       HoldPattern[f_] :> f2_, e___} /;
      
      f1 != f2 -> {s, {f, f1, f2}, m, e}, _List],
  Complement[s2, s1, SameTest -> (First[#1] === First[#2] &)],
  First /@ 
   Complement[s1, s2, SameTest -> (First[#1] === First[#2] &)]}


Bob Hanlon

---- Bob Hanlon <hanlonr at cox.net> wrote: 

=============
state[f_Symbol] :=
  Flatten[#[f] & /@ {DownValues, UpValues}];

stateChanges[s1_List, 
  s2_List] := {Cases[
   Join[s1, s2] //.
    {s___, HoldPattern[f_] :> f1_, m___,
       HoldPattern[f_] :> f2_, e___} /; f1 != f2 ->
     {s, {f, f1, f2}, m, 
      e}, _List],
  Complement[s2, s1, SameTest -> (First[#1] === First[#2] &)],
  First /@ Complement[s1, s2, SameTest -> (First[#1] === First[#2] &)]}

Clear[f]

f[a] = 1;
f[b] = 2;
f[c] = 3;
f[d] = 4;

s1 = state[f];

f[a] = 1;
f[b] = 99;
f[c] =.;
f[d] = 7;
f[m] = 3;

s2 = state[f];

The changes, additions, and deletions are

stateChanges[s1, s2]

{{{HoldPattern[f[b]], 2, 99}, {HoldPattern[f[d]], 4, 7}}, {HoldPattern[f[m]] :> 
   3}, 
   {HoldPattern[f[c]]}}


Bob Hanlon

---- Chris Degnen <tilting at windmills.freeserve.co.uk> 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. 




--

Bob Hanlon

--

Bob Hanlon



  • Prev by Date: Workbench complains about an invalid LinkObject number
  • Next by Date: Re: Precision in Mathematica 6
  • Previous by thread: Workbench complains about an invalid LinkObject number
  • Next by thread: Redirecting input