moobles wrote
AM=M-1
D=M
is behaving differently than
AMD=M-1
 
moobles wrote
oh wait  i might get it...  is it because AMD=M-1 assigns A before updating M whereas AM=M-1 puts M at new value before the D=M?  
this stuff is confusing :(
 
Yes that's correct. (Both your explanation, and that it can be confusing!)
[Please edit you post to remove the implementation of pop_to(). We want students to work out their own "pop" code.]
--Mark