SWI 프롤로그가 이상한 동작으로 멈춤

DieCriminal

그래서 여기에 문제가 있습니다. 저는 프롤로그에서 일종의 "완벽한 일치"프로그램을 만들려고합니다. 당신은 몇 가지를 주면 각 개인은 몇 가지 "특징"을 가지고 있습니다. 프로그램은 그러한 특성에 따라 미래의 결혼에서 발생할 수있는 문제를 반환하도록되어 있습니다.하지만 그렇게하려고하면 상황이 복잡해지면이 문제가 발생합니다.

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.

그래서 더 복잡해지면 어떤 이유로 든 작동하지 않습니다 .. 무슨 일이 일어나고 있는지 정말 이해할 수 없습니다. 나는 프롤로그에 익숙한 두 달 밖에되지 않았습니다.이 문제를 몇 일 동안 가지고 놀았습니다. 운.하지만 이제 시간이 없어서 일을 처리해야합니다. 어떤 도움을 주시면 감사하겠습니다. 미리 감사드립니다.

머리카락 C.

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] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

C # 어설 션에 대한 SWI 프롤로그가 작동하지 않음

분류에서Dev

프로그램이 루프에 멈춤

분류에서Dev

프로그램이주기에 멈춤

분류에서Dev

프로그램이 wait ()에서 멈춤

분류에서Dev

프로그램이 getResponseCode ()에서 멈춤

분류에서Dev

SQL이 쿼리로 멈춤

분류에서Dev

이 검색어로 멈춤

분류에서Dev

창을 옆으로 이동 한 후 Ubuntu가 멈춤

분류에서Dev

창을 옆으로 이동 한 후 Ubuntu가 멈춤

분류에서Dev

SWI 프롤로그 foreach / 2

분류에서Dev

Mac OSX의 프로세스가 '멈춤'및 이상한 CPU 사용량

분류에서Dev

Logitech dinovo edge Bluetooth 동글이 12.10으로 업그레이드 한 후 작동을 멈춤

분류에서Dev

Windows 7이 무작위로 멈춤

분류에서Dev

Ubuntu 19.04 Gnome이 무작위로 멈춤

분류에서Dev

Matlab이 주기적으로 멈춤

분류에서Dev

대화 상자가 거부되면 PyQt 응용 프로그램이 멈춤

분류에서Dev

ajax Post가 "Post"상태로 멈춤

분류에서Dev

13.04-로그온 화면이 멈춤

분류에서Dev

13.04-로그온 화면이 멈춤

분류에서Dev

로그인 후 Ubuntu 17.10이 멈춤

분류에서Dev

작업 표시 줄에 프로그램이 멈춤

분류에서Dev

시작시 기본 응용 프로그램이 멈춤

분류에서Dev

시스템 멈춤 / 거의 멈춤 동안 유용한 로깅 출력 없음

분류에서Dev

tvOS 제스처 인식기가 화면 밖으로 슬라이드 한 후 작동을 멈춤

분류에서Dev

프로그램이 파이프에서 멈춤 (exec ls grep sort)

분류에서Dev

USB 슬롯이 때때로 갑자기 작동을 멈춤

분류에서Dev

38.3.0으로 업데이트 한 후 Thunderbird가 멈춤

분류에서Dev

38.3.0으로 업데이트 한 후 Thunderbird가 멈춤

분류에서Dev

git push로 멈춤

Related 관련 기사

뜨겁다태그

보관