3 ms·
One can encapsulate backtracking simply as an iterator over a stream of answers to a query. The SWI_prolog ecosystem provides a nice "logic engine" abstraction
by PaulTarau 8y ago
One can encapsulate backtracking simply as an iterator over a stream of answers to a query. The SWI_prolog ecosystem provides a nice "logic engine" abstraction for that, see http://www.swi-prolog.org/pldoc/man?section=engines http://www.swi-prolog.org/pldoc/man?section=engines . That gives something similar to Python's yield operation. Backtracking inside an engine allows one to implement some neat algorithms in space proportional to your data, without invoking garbage collection.