그래서 여기에 문제가 있습니다. 저는 프롤로그에서 일종의 "완벽한 일치"프로그램을 만들려고합니다. 당신은 몇 가지를 주면 각 개인은 몇 가지 "특징"을 가지고 있습니다. 프로그램은 그러한 특성에 따라 미래의 결혼에서 발생할 수있는 문제를 반환하도록되어 있습니다.하지만 그렇게하려고하면 상황이 복잡해지면이 문제가 발생합니다.
1 ?- marriage_problems(Couple).
Wifename(sharon,marsh)
Husbandname(randy,marsh)
Possible problem:Wife is lazy while husband is demanding.Not matching.
true ;
Possible problem: Wife is agressive while husband is sensitive.Not matching.
true ;
Possible problem: Wife is sensitive while husband is agressive.Not matching.
true ;
Possible problem: Wife is sensitive while husband is agressive.Not matching.
true ;
Possible problem: Wife is sensitive while husband is agressive.Not matching.
true ;
Possible problem: Wife is sensitive while husband is agressive.Not matching.
true
남편이 .. 일치하지 않는 동안 아내는 민감하고 .. 그리고 그것은 또한 잘못되었습니다. 그리고 여기에 코드가 있습니다 :
couple(wife(name(sharon,marsh),char(economical([stingy,lazy]),sexual([agressive]))),
husband(name(randy,marsh),char(economical([demanding,wasteful]),sexual([sensitive])))).
marriage_problems(Couple):- couple(wife(Wname,char(economical(W_eco),sexual(W_sex))),
husband(Hname,char(economical(H_eco),sexual(H_sex)))),
write('Wife'),write(Wname),nl,
write('Husband'),write(Hname),nl,
marriage_economical_problems(W_eco,H_eco);
marriage_sexual_problems(W_sex,H_sex).
marriage_economical_problems(W_eco,H_eco):- couple(wife(_,char(economical(W_eco),_)),husband(_,char(economical(H_eco),_))),
member(demanding,W_eco),
member(lazy,H_eco),
W_pr=demanding,
H_pr=lazy,
write('Possible problem:Wife is '),write(W_pr),write(' while husband is '),
write(H_pr),write('.Not matching.'),nl;
member(lazy,W_eco),
member(demanding,H_eco),
W_pr=lazy,
H_pr=demanding,
write('Possible problem:Wife is '),write(W_pr),write(' while husband is '),
write(H_pr),write('.Not matching.'),nl.
marriage_sexual_problems(W_sex,H_sex):- couple(wife(_,char(_,sexual(W_sex))),husband(_,char(_,sexual(H_sex)))),
member(agressive,W_sex),
member(sensitive,H_sex),
W_pr=agressive,
H_pr=sensitive,
write('Possible problem: Wife is '),write(W_pr),write(' while husband is '),
write(H_pr),write('.Not matching.'),nl;
member(sensitive,W_sex),
member(agressive,H_sex),
W_pr=sensitive,
H_pr=agressive,
write('Possible problem: Wife is '),write(W_pr),write(' while husband is '),
write(H_pr),write('.Not matching.'),nl.
그리고 이것은 이상하게도 충분합니다.
1 ?- marriage_problems(Couple).
Wifename(sharon,marsh)
Husbandname(randy,marsh)
Possible problem:Wife is lazy while husband is demanding.Not matching.
true ;
Possible problem: Wife is agressive while husband is sensitive.Not matching.
true.
암호:
couple(wife(name(sharon,marsh),char(economical([stingy,lazy]),sexual([agressive]))),
husband(name(randy,marsh),char(economical([demanding,wasteful]),sexual([sensitive])))).
marriage_problems(Couple):- couple(wife(Wname,char(economical(W_eco),sexual(W_sex))),
husband(Hname,char(economical(H_eco),sexual(H_sex)))),
write('Wife'),write(Wname),nl,
write('Husband'),write(Hname),nl,
marriage_economical_problems(W_eco,H_eco);
marriage_sexual_problems(W_sex,H_sex).
marriage_economical_problems(W_eco,H_eco):- couple(wife(_,char(economical(W_eco),_,_,_)),husband(_,char(economical(H_eco),_,_,_))),
member(demanding,W_eco),
member(lazy,H_eco),
W_pr=demanding,
H_pr=lazy,
write('Possible problem:Wife is '),write(W_pr),write(' while husband is '),
write(H_pr),write('.Not matching.'),nl;
member(lazy,W_eco),
member(demanding,H_eco),
W_pr=lazy,
H_pr=demanding,
write('Possible problem:Wife is '),write(W_pr),write(' while husband is '),
write(H_pr),write('.Not matching.'),nl.
marriage_sexual_problems(W_sex,H_sex):- couple(wife(_,char(_,sexual(W_sex))),husband(_,char(_,sexual(H_sex)))),
member(agressive,W_sex),
member(sensitive,H_sex),
W_pr=agressive,
H_pr=sensitive,
write('Possible problem: Wife is '),write(W_pr),write(' while husband is '),
write(H_pr),write('.Not matching.'),nl.
그래서 더 복잡해지면 어떤 이유로 든 작동하지 않습니다 .. 무슨 일이 일어나고 있는지 정말 이해할 수 없습니다. 나는 프롤로그에 익숙한 두 달 밖에되지 않았습니다.이 문제를 몇 일 동안 가지고 놀았습니다. 운.하지만 이제 시간이 없어서 일을 처리해야합니다. 어떤 도움을 주시면 감사하겠습니다. 미리 감사드립니다.
OR 연산자 (;) / 2를 잘못 사용하고 있습니다.
marriage_problems(Couple):- couple(wife(Wname,char(economical(W_eco),sexual(W_sex))),
husband(Hname,char(economical(H_eco),sexual(H_sex)))),
write('Wife'),write(Wname),nl,
write('Husband'),write(Hname),nl,
( marriage_economical_problems(W_eco,H_eco);
marriage_sexual_problems(W_sex,H_sex) ).
괄호가 없으면 married_sexual_problems / 2를 호출 할 때 W_sex와 H_sex가 바인딩 해제됩니다. SWI-Prolog는 증상을 알릴 수 있습니다.
Warning: /home/carlo/prolog/so.pl:81:
Singleton variable in branch: W_sex
Singleton variable in branch: H_sex
Warning: /home/carlo/prolog/so.pl:81:
Singleton variables: [Couple]
또한 커플은 쓸모가 없습니다 ...
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다