Re: Function changes in a program
- To: mathgroup at smc.vnet.net
- Subject: [mg92280] Re: [mg92262] Function changes in a program
- From: Bob Hanlon <hanlonr at cox.net>
- Date: Fri, 26 Sep 2008 06:24:29 -0400 (EDT)
- Reply-to: hanlonr at cox.net
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