O'Reilly logo

Building Parsers with Java™ by Steven John Metsker

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required