tailieunhanh - Learn Prolog Now phần 5

Tập thể dục 2,3 Đây là một từ vựng và ngữ pháp nhỏ nhỏ với một quy tắc định nghĩa một câu gồm năm từ: một bài báo, một danh từ, động từ, và một lần nữa một bài báo và một danh từ. | 68 Chapter 4. Lists All three programs are pretty much the same as a2b 2 though of course they manipulate three lists not two . That is all three can be written by recursing down the lists doing something to the heads and then recursively doing the same thing to the tails. Indeed once you have written combinel you just need to change the something you do to the heads to get combine2 and combines. Now you should have a pretty good idea of what the basic pattern of predicates for processing lists looks like. Here are a couple of list processing exercises that are a bit more interesting. Hint you can of course use predicates that we defined earlier like . member 2 in your predicate definition. 1. Write a predicate mysubset 2 that takes two lists of constants as arguments and checks whether the first list is a subset of the second. 2. Write a predicate mysuperset 2 that takes two lists as arguments and checks whether the first list is a superset of the second. 5 Arithmetic This lecture has two main goals 1. To introduce Prolog s inbuilt abilities for performing arithmetic and 2. To apply them to simple list processing problems using accumulators. Arithmetic in Prolog Prolog provides a number of basic arithmetic tools for manipulating integers that is numbers of the form .-3 -2 -1 0 1 2 3 4. . Most Prolog implementation also provide tools for handling real numbers or floating point numbers such as or X 105 but we re not going to discuss these for they are not particularly useful for the symbolic processing tasks discussed in this course. Integers on the other hand are useful for various tasks such as finding the length of a list so it is important to understand how to work with them. We ll start by looking at how Prolog handles the four basic operations of addition multiplication subtraction and division. Arithmetic examples Prolog Notation 6 2 8 8 is 6 2. 6 2 12 12 is 6 2. 6-2 4 4 is 6-2. 6-8 -2 -2 is 6-8. 6 2 3 3 is 6 2. 7 2 3 3 is 7 2. 1 is the .

TỪ KHÓA LIÊN QUAN
crossorigin="anonymous">
Đã 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.