Circular dependency formulae

Dear igorians,

Is there a way to update the contents of two interdependent waves through a formula?

make/o/n=1 w_a = 0
make/o/n=1 w_b = 0

w_a := w_b
w_b := w_a

print getformula(w_a), getformula(w_b) //prints: w_b  w_a

w_a = 5 // w_b, should become 5
print w_a, w_b // prints: 5  5

print getformula(w_a), getformula(w_b) //prints: w_a [nothing]

w_b = 3
print w_a, w_b // prints: 5  3


edit: so it seems, that the formula gets copied over the previous formula, so setting w_b = 3 does not update w_a.

If you think about it, a circular dependency is a really bad idea. Set w_a to something, which triggers setting w_b to something, which triggers setting w_a...

You might consider a third object, set both w_a and w_b to depend on that, and then interact exclusively with that object.

In general, you should think twice before using dependencies. They create mysterious actions that are hard to track down because the actions are hidden. We have had quite a few "bug" reports that turned out to be the actions of dependencies.

Maybe would could figure out a better way, if you could describe what you are trying to achieve.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
It is not such a bad idea, circular dependency, if done right, i.e. block reentry, or execute a signal action just once.

I want to update a waveA from a waveB by some formula onchange of waveB and vice versa (update waveB from waveA onchange of waveA). This is something akin to a hook for the onchange signal for the wave data type.

I think the described pattern is a side effect of a missing feature in Igor, referencing part of a wave without duplication of memory. Essentially, I want two representations of a single memory space to be updated in two different ways.

For completion, my use-case is the following:
I have wave0 from which I duplicate and transform waveA and waveB according to some respective arithmetic. I display waveA and make some changes to it. I want the changes of waveA to propagate to waveB and ultimately to wave0.

Right now, I have to do this update semi-manually: upon change of waveA, call the function to update waveB. The function to update waveB is stored in a waveA's note as a key (essentially as a dependency), very similar to what "real formulae" do, I can imagine.

best,
_sk
A recursion block in Igor's dependency manager would be a nightmare to write, and make for obscure bugs that are very hard to find.

Your description of your use-case isn't circular. I presume that you want to be able to change either waveA or waveB and have the changes propagate to wave0 and waveB or waveA. I think your method may be the best.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com