Note: limit_stack/2 and trim_stacks/0 have no effect on machines that do not offer dynamic stack expansion. On these machines these predicates simply succeed to improve portability.
loop :- generator, trim_stacks, potentionally_expensive_operation, stop_condition, !.
The prolog top level loop is written this way, reclaiming memory resources after every user query.
This predicate is currently only available on versions that use the stack-shifter to enlarge the runtime stacks when necessary. It's definition is subject to change.