TAILIEUCHUNG - learn prolog now phần 10

Prolog có bốn lệnh thao tác cơ sở dữ liệu: khẳng định, rút lại, asserta, và assertz. Chúng ta hãy xem làm thế nào những được sử dụng. Giả sử chúng ta bắt đầu với một cơ sở dữ liệu rỗng. Vì vậy, nếu chúng ta cung cấp cho các lệnh: niêm yết. | 158 Chapter 10. Cuts and Negation 11 Database Manipulation and Collecting Solutions This lecture has two main goals 1. To discuss database manipulation in Prolog. 2. To discuss inbuilt predicates that let us collect all solutions to a problem into a single list. Database manipulation Prolog has four database manipulation commands assert retract asserta and assertz. Let s see how these are used. Suppose we start with an empty database. So if we give the command listing. we simply get a yes the listing of course is empty. Suppose we now give this command assert happy mia . It succeeds assert commands always succeed . But what is important is not that it succeeds but the side-effect it has on the database. If we now give the command listing. we get the listing happy mia . That is the database is no longer empty it now contains the fact we asserted. Suppose we then made four more assert commands 160 Chapter 11. Database Manipulation and Collecting Solutions assert happy vincent . yes assert happy marcellus . yes assert happy butch . yes assert happy vincent . yes Suppose we then ask for a listing listing. happy mia . happy vincent . happy marcellus . happy butch . happy vincent . yes All the facts we asserted are now in the knowledge base. Note that happy vincent is in the knowledge base twice. As we asserted it twice this seems sensible. So far we have only asserted facts into the database but we can assert new rules as well. Suppose we want to assert the rule that everyone who is happy is naive. That is suppose we want to assert that naive X - happy X . We can do this as follows assert naive X - happy X . Note the syntax of this command the rule we are asserting is enclosed in a pair of brackets. If we now ask for a listing we get happy mia . happy vincent . happy marcellus . happy butch . happy vincent . naive A - happy A

TỪ KHÓA LIÊN QUAN
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.