Function table_ptr get: add outer loop for empty environments