<span style=‘color:red’><span style=‘font-size:14pt;line-height:100%’>Hướng dẫn sử dụng SWI-Prolog</span></span>
<span style=‘color:blue’><b>1. Giới thiệu</b></span>
SWI-Prolog là phần mềm soạn thảo và biên dịch các chương trình Prolog. SWI-Prolog hoàn toàn miễn phí và rất thích hợp cho nghiên cứu và dạy học.
Một số điểm mạnh của SWI-Prolog bao gồm:
- Môi trường thân thiện.
- Biên dịch cực nhanh.
- Hỗ trợ phân tích thực thi.
- Linh động (có thể kết hợp với chương trình viết bằng C).
Website chính thức: <a href=‘http://www.swi-prolog.org’ target=‘_blank’>www.swi-prolog.org</a>
<span style=‘color:blue’><b>2. Cài đặt</b></span>
Download phần mềm SWI-Prolog tại <a href=‘http://www.swi-prolog.org/Download.html’ target=‘_blank’>www.swi-prolog.org/Download.html </a>
Link trực tiếp: <a href=‘http://www.swi-prolog.org/download/stable/bin/w32pl5100.exe’ target=‘_blank’>www.swi-prolog.org/download/stable/bin/w32pl5100.exe</a>
Download SWI-Prolog Editor tại <a href=‘http://www.swi-prolog.org/IDE.html’ target=‘_blank’>www.swi-prolog.org/IDE.html</a>
Link trực tiếp: <a href=‘http://download.bildung.hessen.de/lakk/netzwerk/faecher/informatik/swiprolog/setup.zip’ target=‘_blank’>download.bildung.hessen.de/lakk/netzwerk/faecher/informatik/swiprolog/setup.zip</a>
SWI-Prolog Editor là hỗ trợ phần mềm soạn thảo chương trình Prolog rất trực quan, hiệu quả và tiện dụng. Bạn phải cài đặt SWI-Prolog trước khi cài đặt SWI-Prolog Editor.
<span style=‘color:blue’><b>3. Chạy thử</b></span>
Khởi động SWI-Prolog Editor.
Vào trình đơn File/New
Nhập chương trình sau:
<!–c1–></div><table border=‘0’ align=‘center’ width=‘95%’ cellpadding=‘3’ cellspacing=‘1’><tr><td><b>CODE</b> </td></tr><tr><td id=‘CODE’><!–ec1–>loai_an_co(de).
loai_hung_du(chosoi).
loai_an_thit(X) :- loai_hung_du(X).
an(X, thit) :- loai_an_thit(X).
an(X, co) :- loai_an_co(X).
an(X, Y) :- loai_an_thit(X), loai_an_co(Y).
uong(X, nuoc) :- loai_an_co(X).
uong(X, nuoc) :- loai_an_thit(X).
tieu_thu(X, Y) :- uong(X, Y).
tieu_thu(X, Y) :- an(X, Y).<!–c2–></td></tr></table><div class=‘postcolor’><!–ec2–>
Bấm F9 để biên dịch vào chạy. Kết quả như sau:
<!–QuoteBegin–></div><table border=‘0’ align=‘center’ width=‘95%’ cellpadding=‘3’ cellspacing=‘1’><tr><td><b>QUOTE</b> </td></tr><tr><td id=‘QUOTE’><!–QuoteEBegin–>1 ?- consult(‘D:/Thanh/Prolog/DongVat.pl’).
% D:/Thanh/Prolog/DongVat.pl compiled 0.00 sec, 2,432 bytes
true.<!–QuoteEnd–></td></tr></table><div class=‘postcolor’><!–QuoteEEnd–>
<img src=‘http://www.uit.edu.vn/forum/uploads/post-66-1278598596.png’ border=‘0’ alt=‘user posted image’ />
Tại khung cửa sổ lệnh bên dưới, thực hiện truy vấn:
<!–c1–></div><table border=‘0’ align=‘center’ width=‘95%’ cellpadding=‘3’ cellspacing=‘1’><tr><td><b>CODE</b> </td></tr><tr><td id=‘CODE’><!–ec1–>loai_hung_du(X), tieu_thu(X, Y).<!–c2–></td></tr></table><div class=‘postcolor’><!–ec2–>
Bấm ; để tiếp tục hiển thị các đáp án cho đến khi kết thúc. Kết quả như sau:
<!–QuoteBegin–></div><table border=‘0’ align=‘center’ width=‘95%’ cellpadding=‘3’ cellspacing=‘1’><tr><td><b>QUOTE</b> </td></tr><tr><td id=‘QUOTE’><!–QuoteEBegin–>3 ?- loai_hung_du(X), tieu_thu(X, Y).
X = chosoi,
Y = nuoc ;
X = chosoi,
Y = thit ;
X = chosoi,
Y = de.<!–QuoteEnd–></td></tr></table><div class=‘postcolor’><!–QuoteEEnd–>