A python implementation of TAPL chpt 4