C interface to create a predicate to resolve variable to multiple results

I’m using: SWI-Prolog version 8.0.3
I need to create a predicate in C like the following,
sum(X, Y, s)

The usage of this predicate is to resolve X and Y given s, like

sum(X, Y, 3)
The results should be {X=1, Y=2}, and {X=2, Y=1}, assuming we only want positive integers.

My question is not about the calculation logic to find values for X and Y, but how to return multiple results to the caller. The examples I saw from the prolog reference is all about one single result, like https://www.swi-prolog.org/pldoc/man?section=foreignxmp and https://www.swi-prolog.org/pldoc/man?section=cpp-examples.

Thanks!
Jackson

The last example of cpp-examples does this (average). You must loop over PL_next_solution().

Maybe I misread that example, but it seems to me it reads multiple numbers from A2 and then average them. The average, which is unified with A3, is the only result it creates. What I am looking for is to create multiple results. am I reading it wrong? please let me know. Thanks.

Sorry, I misread. You need Non-deterministic Foreign Predicates (I hope)

Thanks Jan! That’s exactly what I need.