From: Daniel Nugent Date: 2005-07-03T13:44:32+09:00 Subject: FlipFlop Voodoo So I was reading through the retrospective on RedHanded today and saw the piece of flipflops (http://redhanded.hobix.com/inspect/hopscotchingArraysWithFlipFlops.html). Reading it I realized that I didn't quite understand how the flipfloperator worked exactly. So I grabbed the Pickaxe2 and read that it returns true when the state machine is in the set state at the end of the call. Looking at both why's examples, the ones in Pickaxe2, and through a little experimentation of my own and once again reviewing the state transition diagram in Pickaxe2, I figured there must be a typo. See example 1 on pg 342: a = (11..20).collect {|i| (i%4 == 0)..(i%3 == 0) ? i ? nil} a -> [nil, 12, nil, nil, nil, 16, 17, 18, nil, 20] If there isn't a typo and I'm reading it right, then 18 should not be in the output array since the second part of the flipflop should have triggered the state machine to go back to the unset state. Now, Pickaxe2 mentions that when the second condition evaluates to true on the same call as the first condition, it will still output true anyhow. However, it does not explain why this happens or why it also outputs 18 even though 18%3==0 should evaluate to true and push the state machine into the unset state. If I'm missing something vital about this, I'd really appreciate someone taking the time to explain it more thoroughly Because I *think* I understand what's going on here, but my reading of Pickaxe2 would seem to indicate that I don't. -- -Dan Nugent