Re: SWI - passing variable value across rules



Dear Muthumukar,


I am having trouble passing the user's choices (strings 'yes' or 'no')
to rules other than the rules where the user inputs are sought.

There is nothing mysterious about passing variable values. You just do it.
Remember that Prolog variables are like pronouns in regular language.

More below.

I am
reproducing the full code below:

/*KNOWLEDGE BASE*/

issue(product_mat_date,hpls,gcdm).
issue(product_mat_date,hpls,daily_nt).
issue(limit,hcc,gcdm).
isrelatedto(limit,basel).
isrelatedto(hpls,local_development).
isrelatedto(hpls,jacob).
isrelatedto(daily_nt,canada).
isrelatedto(hpls,ajay).

/*RULE TO GET USER CHOICES AND INPUTS AND DISPLAY RELEVANT ITEMS FROM
KNOWLEDGE BASE AND ALSO ADD NEW FACTS WITH DYNAMIC PREDICATE
ISRELATEDTO2*/

go:- writeq('Please provide a file name'),
read(File),
assertz(file(File)),
isrelatedto(File,Name),
writeq(Name),writeq('Want more? Type yes or no'),read(Choice),
writeq('Want to add new facts? Type yes or no'),read(Choice2),
assertz(sechoice(Choice2)),
choice(Choice).

choice(yes):-isrelatedto(file(File),Name),choice2(sechoice(X)).

Prolog should have complained to you about this clause. You have
singleton variables. In regular language that's like having a pronoun
without an antecedent. File, Name, and X do not refer to anything.


choice(no):-writeq('Thank you for using the
system'),choice2(sechoice(X)).


At first glance it looks like you want to say something like this:

choice(yes, File, Name, X) :-
isrelatedto(file(File),Name),
choice2(sechoice(X)).
choice(no, _, _, X) :-
writeq('Thank you for using the system),
choice2(sechoice(X)).


That means changing the last goal in go/0 to something like this:

choice(Choice, File, Name, Choice2).


choice2(yes):-writeq('Please enter file
name'),read(Newfile),writeq('Please enter connected to
entity'),read(Connectedto),assertz(isrelatedto2(Newfile,Connectedto)).

choice2(no):-writeq('Thank you for using the system').
***********************************************

choice2(sechoice(X)) never seems to get translated to choice2(yes) or
choice2(no).

That would be impossible. No matter what value X has, sechoice(X) will
never unify with either yes or no. It looks like you want to say

choice2(X) instead of choice2(sechoice(X)).

However, isrelatedto(File,Name) which appears in the go
rule is correctly getting converted based on user input.

Any help is appreciated.


There seem to be some other problems with the code, but that should give
you the general idea. To pass variables, make them arguments.

Good luck!

Bill
.



Relevant Pages

  • Re: SWI - passing variable value across rules
    ... Bill Spight wrote: ... I am having trouble passing the user's choices ... to rules other than the rules where the user inputs are sought. ... I think you can change your codes in the following way: ...
    (comp.lang.prolog)
  • SWI - passing variable value across rules
    ... I am writing a Prolog program for a semantic net (basically a knowledge ... and also add new facts if the user so wishes. ... to rules other than the rules where the user inputs are sought. ... /*RULE TO GET USER CHOICES AND INPUTS AND DISPLAY RELEVANT ITEMS FROM ...
    (comp.lang.prolog)
  • Re: SWI - passing variable value across rules
    ... I am writing a Prolog program for a semantic net (basically a knowledge ... and also add new facts if the user so wishes. ... to rules other than the rules where the user inputs are sought. ...
    (comp.lang.prolog)