Backtracking Problem

Posted by Joshua Green on Stack Overflow See other posts from Stack Overflow or by Joshua Green
Published on 2010-04-09T00:16:29Z Indexed on 2010/04/09 0:23 UTC
Read the original article Hit count: 608

Filed under:
|
|

Could someone please guide me through backtracking in Prolog-C using the simple example below?

Here is my Prolog file:

likes( john, mary ).

likes( john, emma ).

likes( john, ashley ).

Here is my C file:

#include...

term_t tx;
term_t tv;
term_t goal_term;
functor_t goal_functor;

int main( int argc, char** argv )
{
    argv[0] = "libpl.dll";
    PL_initialise( argc, argv );
    PlCall( "consult( swi( 'plwin.rc' ) )" );
    PlCall( "consult( 'likes.pl' )" );

    tv = PL_new_term_ref( );
    PL_put_atom_chars( tv, "john" );
    tx = PL_new_term_ref( );
    goal_term = PL_new_term_ref( );
    goal_functor = PL_new_functor( PL_new_atom( "likes" ), 2 );
    PL_cons_functor( goal_term, goal_functor, tv, tx );

    PlQuery q( "likes", ??? );
    while ( q.next_solution( ) )
     {
      char* solution;
      PL_get_atom_chars( tx, &solution );
      cout << solution << endl;
     }

    PL_halt( PL_toplevel() ? 0 : 1 );
}

What should I replace ??? with?

Or is this the right approach to get all the backtracking results generated and printed?

Thank you,

© Stack Overflow or respective owner

Related posts about swi-prolog

Related posts about vs2008