-
Notifications
You must be signed in to change notification settings - Fork 0
/
swilisp.c
65 lines (51 loc) · 1.3 KB
/
swilisp.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/* TEST */
#include "SWI-Prolog.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
void plus_test(int a, int b){
char *argv[] = {"swilisp", "--quiet", NULL};
int args = 2;
//#ifdef READLINE /* Remove if you don't want readline */
// PL_initialise_hook(install_readline);
//#endif
if ( !PL_initialise(args, argv) ){
PL_halt(1);
}
printf("Calculating a+x=b... using the plus predicate\n");
predicate_t tmp;
// ask for 3 terms
term_t t = PL_new_term_refs(3);
// define our terns (example is plus(2,x,5) // 2+x=5
PL_put_integer(t, a);
PL_put_integer(t+2, b);
PL_put_variable(t+1);
// get access to predicate
tmp = PL_predicate("plus", 3, "database");
// make the predicate query
qid_t query = PL_open_query(NULL, PL_Q_NORMAL, tmp, t);
// check for solutions
int result = PL_next_solution(query);
if(result){
int x;
PL_get_integer(t+1, &x);
printf("Solution: %d\n", x);
}
else{
printf("No solution found\n");
}
PL_close_query(query);
PL_halt(PL_toplevel() ? 0 : 1);
}
int main(int argc, char **argv){
/* #ifdef READLINE /* Remove if you don't want readline
PL_initialise_hook(install_readline);
#endif
if ( !PL_initialise(argc, argv) ){
PL_halt(1);
}
printf("Test Complete\n");*/
plus_test(4, 9);
//PL_halt(PL_toplevel() ? 0 : 1);
}