Yielding prolog engines from within a foreign predicate

I would love to do a PR but studying up on the swipl internals is probably going to take longer than my holiday. But I’ll see what I can do :slight_smile: .

I wonder if we can’t expand the way nondeterministic predicates work to also allow yielding, as nondets already have a way to pass in a bit of data between calls. All that would be required is some way to differentiate between being called due to needing a next result, or being called because of continuing from a yield. Exploiting the exception mechanism could maybe be used for returning the actual yield term, and the return code could be used to signify that a yield should happen (maybe everything above 256 can be interpreted as a yield code?)
Also, perhaps predicates that can be expected to yield should be registered somewhat differently, to prevent them from being called from within a context that doesn’t allow yielding.