Mutually Recursive Zombies on a Trampoline
It’s late at night. The kids are all tucked snuggly in their beds and I am ready to explore mutual recursion on my own in Clojure after doing some reading of Programming Clojure. What better subject to explore them with then zombies? In this example we have two zombies – zombie1 and zombie2. Let’s represent each zombie as a sequence: (def zombie1 '("z1_head", "z1_r_arm" "z1_l_arm" "z1_torso" "z1_r_leg" "z1_l_leg")) (def zombie2 '("z2_head", "z2_r_arm" "z2_l_arm" "z2_torso" "z2_r_leg" "z2_l_leg")) zombie1 is ready to take a bite of zombie2’s left leg, since it is nice and tasty there at the end. Once zombie1 takes a bite, the body part will be added to its own sequence – but in the second position, so that the head is always first and ready to take another bite. So, if zombie2 just stood still and let itself be eaten, after one bite, zombie1 would look like this ...