Author |
Message |
Matt Wilso #1 / 3
|
 Prolog global variables?
Hey all, I'm trying to write a prolog program which kinda keeps track of whats going on... heres an example; process([where, is, X], [X, is, in, Y]) :- isin(X,Y). this is called via another rule called "go", and then rules are checked etc and putting in [where, is, mcdonalds]. might return [mcdonalds, is, in, leeds]. thats all fine and dandy, working great. Now the problem, I have to then implement a [what, is, it] section which I thought was going to be easy but for the life of me I can't get it to work as wanted. So yea, if I put in [what, is, it] after the last one I should get [mcdonalds, is, a, restaurant] which i've got handled. I just want to know (finally) how to store a global variable of what "it" is. Something like; process([where,is,X], [X,is,in,Y]) :- isin(X,Y), GlobalVar = Y. Was what I was thinking of and then; process([what,is,it], A) :- process([what,is,GlobalVar], A). But that doesn't work and just returns (assuming) the variable allocation pointer or something like that (e.g. _L203). So any help anyone can offer will be appreciated. Matt -- http://www.*-*-*.com/ - Your best source for free scripts and programs! It is a hard matter, my fellow citizens, to argue with the belly, since it has no ears. -- Marcus Porcius Cato
|
Sat, 08 May 2004 07:02:13 GMT |
|
 |
Bart Demoe #2 / 3
|
 Prolog global variables?
"Matt Wilson Quote: > process([where, is, X], [X, is, in, Y]) :- isin(X,Y). > this is called via another rule called "go", and then rules are checked > etc and putting in [where, is, mcdonalds]. might return [mcdonalds, is, > in, leeds]. thats all fine and dandy, working great. > Now the problem, I have to then implement a [what, is, it] section which > I thought was going to be easy but for the life of me I can't get it to > work as wanted. So yea, if I put in [what, is, it] after the last one I > should get [mcdonalds, is, a, restaurant] which i've got handled. I just > want to know (finally) how to store a global variable of what "it" is. > Something like; > process([where,is,X], [X,is,in,Y]) :- isin(X,Y), GlobalVar = Y. > Was what I was thinking of and then; > process([what,is,it], A) :- process([what,is,GlobalVar], A).
Without trying to give you a complete solution, here is something that might help you construct one: process/2 seems to be something that given a sentence, returns another sentence + some more information which you want to put in a global variable; I suggest that you put it as an extra argument in the process predicate, and haps you need 2 of those argument, one that gets in and one that gets out; the information it carries is related to the focus of the conversation you seem to be simulating; so it could be a list like [it(macdonalds), where(leeds), when(dunno)] initially, it is empty; rules for process/4 become a bit more complicated; as an example: process([where,is,X],[X,is,in,Y],InfoIn,InfoOut) :- findlocation(InfoIn,Y), update_it(X,InfoIn,InfoOut). you use process/4 in a recusive predicate like conversation(Info) :- userinput(User), process(User,Answer,Info,NewInfo), display_answer(Answer), conversation(NewInfo). Does that work for you ? Cheers Bart Demoen
|
Sat, 08 May 2004 16:34:49 GMT |
|
 |
Matt Wilso #3 / 3
|
 Prolog global variables?
Quote:
> Without trying to give you a complete solution, here is something that > might help you construct one: > process/2 seems to be something that given a sentence, returns another > sentence + some more information which you want to put in a global > variable; I suggest that you put it as an extra argument in the process > predicate, and haps you need 2 of those argument, one that gets in and > one that gets out; the information it carries is related to the focus of > the conversation you seem to be simulating; so it could be a list like > [it(macdonalds), where(leeds), when(dunno)] initially, it is empty; > rules for process/4 become a bit more complicated; as an example: > process([where,is,X],[X,is,in,Y],InfoIn,InfoOut) :- > findlocation(InfoIn,Y), > update_it(X,InfoIn,InfoOut). > you use process/4 in a recusive predicate like > conversation(Info) :- > userinput(User), > process(User,Answer,Info,NewInfo), > display_answer(Answer), > conversation(NewInfo). > Does that work for you ? > Cheers > Bart Demoen
Hrm, OK I think I understand the direction this is going in, i'm trying; go :- Git = '', write('Please type in a question > '), read(Question), process(Question, Answer, Git), write(Answer), nl, (Question=[bye];go). process([what, is, X], [X, is, a, Y], X) :- isa(X, Y). process([what, is, it], A, G) :- process([what, is, G], A, _). isa(mcdonalds, restaurant). I tried this (basically, with some more stuff), by executing the rule go. and then typing in [what, is, mcdonalds]. I expected [mcdonalds, is, a, restaurant] as the reply with Git now set to "mcdonalds". So when I execute [what, is, it], it should reply with [mcdonalds, is, a, restaurant]. *However*, as i'm sure you've realised whats wrong already, what I get is; Please type in a question > [what, is, mcdonalds]. No. ?- Which of course isn't what I wanted. I assume it is because of the final X in the first process statement with it conflicting with the Git and member of Question being processed... I'm really confused please give me some more hints! Thanks for your help. Matt -- http://www.mattsscripts.co.uk - Your best source for free scripts and programs! <Knghtbrd> Feanor - license issues are important. If we don't watch our arses now, someone's gonna come up and bite us later...
|
Sun, 09 May 2004 04:06:25 GMT |
|
|
|