Skip to content

How to write a predicate with the PREDICATE macro that supports multiple bindings for one variable? #4

@airballking

Description

@airballking

I have a beginner question about the SWI-Prolog C++ interface. If this is the wrong place to post such a question, I apologize and ask: Where should I ask such a question?

I want to create a predicate foo_bar/1 that binds two possible solutions to its variable. Meaning, I want the following behavior of the resulting call in prolog:

?- foo_bar(X).
X = foo ;
X = bar.

In Prolog, I'd implement it like this:

foo_bar(X) :-
  X = foo;
  X = bar.

Now, I'd like to implement the same behavior using the C++ interface. I tried this:

PREDICATE(foo_bar, 1) {
    PL_A1 = std::string("foo").c_str();
    PL_A1 = std::string("bar").c_str();
    return true;
}

But it only returns the first binding:

?- foo(X).
X = foo.

Does the C++ interface support implementing this type of predicate? If yes, how can I do it?

Thank you very much in advance for your support!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions