2017-05-24 5 views
5

저는 프롤로그를 처음 사용하고 있으며이 코드를 작성했지만이 프롤로그 파일을 독립 실행 형 EXE 파일로 만들고 싶습니다. . swi-prolog를 사용하여 파일을 참조하고 있습니다. swi-prolog를 사용하여이 프로그램을 실행 가능하게 만드는 단계별 자습서가 필요합니다. 'computer.pl'로 저장했습니다. 아래 코드를 참조하십시오. 코드가 빠른 읽기에 잘 휴대용 보이는이 프롤로그 파일을 독립 실행 형 EXE 파일로 만들고 싶습니다.

main :- identify. 

identify :- 
    write('Welcome to Micro-Computer troubleshooting'), 
    nl, 
    write('Please do not forget to type all your answers with a period(.) in the end'), 
    nl, 
    retractall(known(_,_,_)),   % clear stored information 
    diagnosis(X), 
    nl, 
    write('The problem is: '), 
    nl, 
    writeListByLine(X). 
identify :- 
    nl, 
    write('I can not identify the problem'). 

writeListByLine([]). 
writeListByLine([H|T]) :-     % write answers in newline 
    write(H), 
    nl, 
    writeListByLine(T). 

%%%%%%%%%%%%%%%%%%%%%%%% Audio Sound Card not detected %%%%%%%%%%%%%%%%%% 

diagnosis(['damaged sound card']) :- 
    problem('Audio Sound Card not detected'), 
    nl, 
    write('>> remove damaged sound card and replace with a new sound card <<'), 
    nl, 
    question_1('is the sound card working?'). 

diagnosis(['sound card not installed']) :- 
problem('Audio Sound Card not detected'), 
nl, 
write('>> install new sound card <<'), 
nl, 
question_2('can your computer detect the new sound card?'). 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Audio Driver Warning %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 

diagnosis(['driver conflict']) :- 
    problem('Audio Driver Warning'), 
    nl, 
    write('>> uninstall previous audio drivers <<'), 
    nl, 
    question_1('is the audio driver working now?'). 

diagnosis(['incompatable audio driver']) :- 
problem('Audio Driver Warning'), 
nl, 
write('>> install the appropriate audio driver for your computer <<'), 
nl, 
question_2('is your computer still showing driver Warning?'). 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Scratchy Sound %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 

diagnosis(['signal interference']) :- 
    problem('Scratchy Sound'), 
    nl, 
    write('>> stay away from radio frequency sources <<'), 
    nl, 
    question_1('is the sound working fine now?'). 

diagnosis(['bad speaker']) :- 
    problem('Scratchy Sound'), 
    nl, 
    write(' >> connect a ear phone to the computer <<'), 
    nl, 
    question_2('is the ear phone giving scratchy sound also?'). 

diagnosis(['bad speaker']) :- 
    problem('Scratchy Sound'), 
    nl, 
    write('>> replace speaker <<'), 
    nl, 
    question_3('it should be working fine now ?'). 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Num lock stays off at startup %%%%%%%%%%%%%%%%%%%%%%%%% 

diagnosis(['num lock shut off in BIOS']) :- 
    problem('Num lock stays off at startup'), 
    nl, 
    write('>> turn on num lock in BIOS <<'), 
    nl, 
    question_1('does num lock on at startup?'). 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Invalid Drive Specification Error %%%%%%%%%%%%%%%%%%%%%%%%% 

diagnosis(['drive not yet formatted']) :- 
    problem('Invalid Drive Specification Error'), 
    nl, 
    write('>> format your drive <<'), 
    nl, 
    question_1('does your drive shows the drive letter?'). 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Mouse Pointer Jerks Onscreen %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 

diagnosis(['mouse ball or rollers are dirty']) :- 
    problem('Mouse Pointer Jerks Onscreen'), 
    nl, 
    write('>> clean mouse mechanism <<'), 
    nl, 
    question_1('does the mouse still jerks on onscreen?'). 

diagnosis(['damaged mouse']) :- 
problem('Mouse Pointer Jerks Onscreen'), 
nl, 
write('>> connect the mouse to another computer <<'), 
nl, 
write('>> replace mouse <<'), 
nl, 
question_2('does the mouse still jerks on onscreen?'). 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
%%%%%%%%%%%%%%%%%%%% System Cant find my Hard Drive %%%%%%%%%%%%%%%%%%%%%%% 

diagnosis(['boot priority error']) :- 
problem('System Cant find my Hard Drive'), 
nl, 
write('>> set hard drive as the first booting device <<'), 
nl, 
question_1('does your hard drive now load at startup?'). 

diagnosis(['crashed hard drive']) :- 
problem('System Cant find my Hard drive'), 
nl, 
write('>> insert another hard drive to your computer,if the hard drive load at startup then previous hard drive has crashed <<'), 
nl, 
question_2('does your system recognize the hard drive?'). 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
%%%%%%%%%%%%%%%%%%%%%%%%%%%% Random shutdown when working on computer %%%%%%%%%%%%%%% 

diagnosis(['over heating']) :- 
problem('Random shutdown when working on computer'), 
question_1('does your computer get very hot when working?'). 

diagnosis(['dusty vent']) :- 
problem('Random shutdown when working on computer'), 
question_2('is their blockage or dust in the system vent?'). 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
%%%%%%%%%%%%%%%%%%%%%%%% computer freezes randomly %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 

diagnosis(['hard drive is full']) :- 
problem('computer freezes randomly'), 
question_1('is your hard drive full'). 

diagnosis(['system RAM is faulty']) :- 
problem('computer freezes randomly'), 
question_2('does your system shows blue-screen errors at startup?'). 

diagnosis(['bad hard drive']) :- 
problem('computer freezes randomly'), 
question_3('does your hard drive make loud noise?'). 

diagnosis(['bad hard drive']) :- 
problem('computer freezes randomly'), 
question_4('does your computer boot slowly?'). 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
%%%%%%%%%%%%%%%%%%%%%%%%% Blue-screens %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 

diagnosis(['Bad memory modules']) :- 
problem('Blue-screens'), 
nl, 
write('>> check memory with memtester and see if you get errors <<'), 
nl, 
write('>> if you do get errors and have more than one slots occupied <<'), 
nl, 
write('>> then test one by one and see if it works <<'), 
nl, 
question_1('did the test work?'). 

diagnosis(['corrupt drivers installed']) :- 
problem('Blue-screens'), 
nl, 
write('>> perform system restore to uninstall the corrupted drivers <<'). 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
%%%%%%%%%%%%%%%%%%%%%%%%%%% Monitor is blank %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 

diagnosis(['no power to monitor']) :- 
problem('Monitor is blank'), 
question_1('check if the monitor connected to power source?'). 

diagnosis(['monitor not connected to computer']) :- 
problem('Monitor is blank'), 
question_2('is the monitor connected to the CPU?'). 

diagnosis(['screen-saver enabled']) :- 
problem('Monitor is blank'), 
question_3('check if screen-saver is enabled'). 

diagnosis(['display card not connected']) :- 
problem('Monitor is blank'), 
question_4('is display card connected?'). 








%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
%%%%%%%%%%%%%%%% This is where the asking starts %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
problem(X):- menuask(problem,X,['Audio Sound Card not detected', 
       'Audio Driver Warning', 'Scratchy Sound', 
       'Num lock stays off at startup','Invalid Drive Specification Error', 
       'Mouse Pointer Jerks Onscreen', 'System Cant find my Hard Drive', 'Random shutdown when working on computer', 
       'computer freezes randomly', 'Blue-screens', 'Monitor is blank']).   % shows menu 
question_1(X):- ask(question_1,X). 
question_2(X):- ask(question_2,X). 
question_3(X):- ask(question_3,X). 
question_4(X):- ask(question_4,X). 
question_5(X):- ask(question_5,X). 
question_6(X):- ask(question_6,X). 
question_7(X):- ask(question_7,X). 
question_8(X):- ask(question_8,X). 
question_9(X):- ask(question_9,X). 
question_10(X):- ask(question_10,X). 
question_11(X):- ask(question_11,X). 
question_12(X):- ask(question_12,X). 

% "ask" only deals with simple yes or no answers. a "yes" is the only 
% yes value. any other response is considered a "no". 

ask(Attribute,Value):- 
    known(yes,Attribute,Value),  % succeed if we know its true 
    !.        % and dont look any further 
ask(Attribute,Value):- 
    known(_,Attribute,Value),   % fail if we know its false 
    !, fail. 

ask(Attribute,_):- 
    (known(yes,Attribute,_)),   % fail if we know its some other value. 
    !, fail.       % the cut in clause #1 ensures that if 
            % we get here the value is wrong. 
ask(A,V):- 
    write(A:V),      % if we get here, we need to ask. 
    write('? (yes or no): '), 
    read(Y),       % get the answer 
    asserta(known(Y,A,V)),   % remember it so we dont ask again. 
    Y = yes.       % succeed or fail based on answer. 

% "menuask" is like ask, only it gives the user a menu to to choose 
% from rather than a yes on no answer. 

menuask(Attribute,Value,_) :- 
    known(yes,Attribute,Value),  % succeed if we know 
    !. 
menuask(Attribute,_,_) :- 
    known(yes,Attribute,_),   % fail if its some other value 
    !, fail. 

menuask(Attribute,AskValue,Menu):- 
    nl,write('What is the '),write(Attribute),write('?'),nl, 
    display_menu(Menu), 
    write('Enter the number of choice> '), 
    read(Num),nl, 
    pick_menu(Num,AnswerValue,Menu), 
    asserta(known(yes,Attribute,AnswerValue)), 
    AskValue = AnswerValue.   % succeed or fail based on answer 

display_menu(Menu) :- 
    disp_menu(1,Menu), !.    % make sure we fail on backtracking 

disp_menu(_,[]). 
disp_menu(N,[Item | Rest]) :-  % recursively write the head of 
    write(N),write(' : '),write(Item),nl, % the list and disp_menu the tail 
    NN is N + 1, 
    disp_menu(NN,Rest). 

pick_menu(N,Val,Menu) :- 
    integer(N),      % make sure they gave a number 
    pic_menu(1,N,Val,Menu), !.  % start at one 
    pick_menu(Val,Val,_).    % if they didn't enter a number, use 
            % what they entered as the value 

pic_menu(_,_,none_of_the_above,[]). % if we've exhausted the list 
pic_menu(N,N, Item, [Item|_]).  % the counter matches the number 
pic_menu(Ctr,N, Val, [_|Rest]) :- 
    NextCtr is Ctr + 1,    % try the next one 
    pic_menu(NextCtr, N, Val, Rest). 
+1

자습서 사이트가 아닙니다. 당신이 원하는 것을 얻기 위해 지금까지 시도한 것은 무엇입니까? – DarkCygnus

답변

3

, 당신은 그것에서 .exe 파일을 생성하기 위해 GNU 프롤로그를 사용할 수 있습니다. 코드가 foo.pl라는 이름의 파일에 저장되어 있다고 가정하면, 당신은 당신의 실행 파일을 생성하기 위해 GNU 프롤로그 gplc 명령 줄 유틸리티를 사용할 수 있습니다

$ gplc --no-top-level -o foo.exe foo.pl 

을하지만 먼저 당신은 상단에있는 코드에 다음과 같은 지침을 추가해야합니다 gplc 유틸리티는 dynamic/1 지시없이 오류를보고합니다

:- initialization(main). 
:- dynamic(known/3). 

: 파일의. foo.exe을 실행하면 다음이 인쇄됩니다 :

$ ./foo.exe 
Welcome to Micro-Computer troubleshooting 
Please do not forget to type all your answers with a period(.) in the end 

What is the problem? 
1 : Audio Sound Card not detected 
2 : Audio Driver Warning 
3 : Scratchy Sound 
4 : Num lock stays off at startup 
5 : Invalid Drive Specification Error 
6 : Mouse Pointer Jerks Onscreen 
7 : System Cant find my Hard Drive 
8 : Random shutdown when working on computer 
9 : computer freezes randomly 
10 : Blue-screens 
11 : Monitor is blank 
Enter the number of choice> 

P. GNU Prolog는 진정한 .exe 파일을 생성 할 수있는 소수의 Prolog 컴파일러 중 하나이며, GNU Prolog도 설치하지 않고도 다른 사람들에게 배포 할 수 있습니다.

+0

나는 GNU Prolog를 지금 설치하고 당신이 말한대로 할 것이다. 고마워요. 정말로 당신의 도움에 감사드립니다. 나는 그것이 어떻게되는지 알려줄 것입니다. – osca1

+0

GNU Prolog를 설치했고 코드에 지시문을 삽입했지만 gplc 명령 줄이 열리고 닫힙니다. 내가 그 문제는 그 windows10에서 실행 중인지 모르겠다. – osca1

+1

필자는 Windows 10에 액세스 할 수 없지만 일부 종속성이 누락 된 것으로 보입니다. 'gplc'에 의해 호출되어 지원되는 C 컴파일러가 해당 운영 체제에서 원시 코드를 생성하는 것 같습니다. –