13.10. List Applications
The combination of the list data structure and the ability to define recursive rules allows you to create several highly reusable algorithms. All the Logikus programs in this chapter are included in this book's CD in .txt files. You can open these files with any editor and copy and paste them into your own programs.
13.10.1. Member
The member program is probably the most fundamental and most reused algorithm in logic programming. The program (from file member.txt) is
member(X, [X | Rest]); member(X, [Y | Rest]) :- member(X, Rest);
Figure 13.7 shows this program in use.
Figure 13.7. The member program. The query uses the classic logic program member to extract chess champs of the late 20th century from a list.
A high-level ...
Get Building Parsers with Java™ now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.