I am using the following code to temporarily change the occurs check flag:
with_occurs_check(G) :- current_prolog_flag(occurs_check, F), setup_call_cleanup(