PREDICATE( name, arity )

This is a discussion on PREDICATE( name, arity ) within the General AI Programming forums, part of the and's Artificial Intelligence Boards category; Suppose I have the program below: Code: #include files PREDICATE( add, 3 ) { return A3 = (long)A1 + (long)A2; ...

  1. #1
    Registered User
    Join Date
    Mar 2010

    PREDICATE( name, arity )

    Suppose I have the program below:
        #include files
        PREDICATE( add, 3 )
            return A3 = (long)A1 + (long)A2;
        int main( int argc, char** argv )
            PlEngine e( argv[0] );
            PlCall( "consult('')" );
            PL_halt( PL_toplevel() ? 0 : 1 );
    When I compile it, it links Prolog and C++ and then launches the Prolog command prompt.

    All I have in is
        :- use_module( library(shlib) ).
    When I type listing at the Prolog prompt, I get
        Foreign: add/3
    So far, everything is simple and as expected. My question is how do I use the result of some other subroutine, say a class, in my foreign predicate add? Let's say I have a class somewhere in my program that calculates some x and y. Obviously x and y would be private or protected members of that class' header file. How do I use x and y in my add predicate? For instance, if I wanted to return the sum of x and y and first and second arguments of add?


  2. #2
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Cambridge, UK
    well the you can a member fucntion which your calls to get the private or the protected data member. There is no difference in that. You program what ever you want in C++ and then use your Prolog API and warp it up which then provides a neat way of interfacing it between the prolog and C/C++.

    I suppose you know how to get the results in prolog?

    add( 10,20, R ).
    The R variable would hold the sum of 10 and 20 as Prolog wouldn't return the sum instead instead true/false.

    Life is like riding a bicycle. To keep your balance you must keep moving - Einstein

Popular pages Recent additions subscribe to a feed

Tags for this Thread

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21