Advertisement
quantumech

Untitled

May 23rd, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.10 KB | None | 0 0
  1. #include <cinterf.h>
  2. #include <stdio.h>
  3.  
  4. int main()
  5. {
  6.     // 1) Create a 'VarString' object called 'queryValue'
  7.     XSB_StrDefine(queryValue);
  8.  
  9.     // 2) Initialize XSB
  10.     if(xsb_init_string("path/to/XSB"))
  11.     {
  12.         printf("++XSB failed to initialize with error: %s\n", xsb_get_init_error_message());
  13.         exit(-1);
  14.     }
  15.     else
  16.     {
  17.         // 3) Load XSB script with defined terms such as 'f(a,b,c)' 'f(1,2,3)' etc.
  18.         xsb_command_string("consult('./script.P').");
  19.  
  20.         // 4) Query XSB with 'f(X,Y,Z)' and pass first result of query into 'queryValue' variable declared above
  21.         // with each value of the result seperated by ',''s. Ex. 'a,b,c' for 'X=a, Y=b, Z=c', '1,2,3' for 'X=1, Y=2, Z=3' etc.
  22.         // Returns XSB_SUCCESS if query returns a result
  23.         if(xsb_query_string_string("f(X,Y,Z).", &queryValue, ",") == XSB_SUCCESS)      
  24.         {
  25.             // Keep passing query results into 'queryValue' until there are no more values from the query
  26.             while(xsb_next_string(&queryValue, ",") == XSB_SUCCESS)
  27.             {
  28.                 // Print result of query
  29.                 printf("Query result: %s\n", queryValue.string);   
  30.             }
  31.         }
  32.  
  33.         // Terminate XSB
  34.         xsb_close();
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement