Interfacing C++ and Prolog to work out factorial
I would like to work out a number's factorial. My factorial rule is in a Prolog file and I am connecting it to a C++ file. Can someone please tell me what is wrong with my interfacing C++ to Prolog?
factorial( 1, 1 ):-
factorial( X, Fac ):-
X > 1,
Y is X - 1,
factorial( Y, New_Fac ),
Fac is X * New_Fac.
I get the Prolog prompt, which is what the last line does. But I don't get the result of the factorial calculation, such as:
int main( int argc, char** argv )
argv = "libpl.dll";
PlCall( "consult('factorial.pl')" );
cout << "Enter your factorial number: ";
cin >> nf;
tf = PL_new_term_ref();
PL_put_integer( tf, nf );
tx = PL_new_term_ref();
goal_term = PL_new_term_ref();
goal_functor = PL_new_functor( PL_new_atom("factorial"), 2 );
rval = PL_cons_functor( goal_term, goal_functor, tf, tx );
PL_halt( PL_toplevel() ? 0 : 1 );
?- factorial( 5, X ).
X = 120
What am I missing?