Record the variable nodes list as well when unifying a pattern for later use.