[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Trying to add facts during runtime in VC++
From: |
Vic Bancroft |
Subject: |
Re: Trying to add facts during runtime in VC++ |
Date: |
Tue, 18 Feb 2003 01:22:47 -0500 (EST) |
On Mon, 17 Feb 2003 address@hidden wrote:
> Lindsey Spratt said:
> >
> > On Monday, February 17, 2003, at 04:30 PM, Joseph N. Fiore wrote:
> >
> >> Now. While the C program is running, it learns from an outside
> >> source, that John has a son named Joe. How do I tell GNU-Prolog from
> >> the C program, the new fact? parent(john,joe).
> >
> > Make sure that you have declared parent/2 dynamic.
This can be done in gprolog with a directive in you prolog,
:- dynamic( parent/2 ).
> > Then I think you want to evaluate a gprolog query using the builtin
> > assert/1:
> >
> > assert(parent(john, joe)).
Well actually, you need assertz/1. For porting convenience assert/1 can be
easily added.
> Maybe I wasn't clear. How do an assert from a C program at runtime?
> The only C source code examples I've seen are for queries with a Pl_Query.
Perhaps after reading gprolog/examples/ExamplesC/new_main_c. Lindsey's
answer will make more sense. If you make modifications, such as,
int func, assert, parent;
WamWord arg[10], trm[10];
char str[100];
char *sol[100];
int i, nb_sol = 0;
Bool res;
Start_Prolog(argc, argv);
func = Find_Atom("anc");
assert = Find_Atom("assertz");
parent = Find_Atom("parent");
arg[0] = Mk_String("john");
arg[1] = Mk_String("joe");
trm[0] = Mk_Compound( parent, 2, arg);
Pl_Query_Begin(TRUE);
res = Pl_Query_Call(assert, 1, trm);
Pl_Query_End(PL_RECOVER);
You will notice that now joe has ancestors,
$ ./new_main
Enter a name (or 'end' to finish): joe
solution: john
solution: bob
solution: jane
solution: mary
solution: paul
solution: peter
6 solution(s)
more,
l8r,
-------------------------------------------------------------------
Victor Bancroft, Principal Engineer, Zvolve Systems [v]770.551.4505
1050 Crown Pointe Pkwy, Suite 300, Atlanta GA 30338 [f]770.551.4509
Fellow, Artificial Intelligence Center [v]706.542-0358
Athens, Georgia 30602, U.S.A http://ai.uga.edu/~bancroft