Finally, we call main again so that we keep displaying the menu until we're done. At the end, we'll call read/1 to read in a variable (aptly named Choice) and then we'll call a predicate called run_opt and pass in whatever choice is. For this first simple example, we'll just give the user the choices to run a query or quit. Main is what we're going to use to actually print the menu, so we'll start with a normal predicate definition and then we're just going to print out whatever we want/need for the menu. Notice that the line starts with a :- and ends with a period. This is accomplished with the following line: The first thing to do is to load your KB. Because the plan is to compile this into an executable, I'll call this.
Grand_father(X,Z) :- father(X,Y), parent(Y,Z). % This is the Prolog version of the family example It's just a basic KB that we can start with. This KB comes directly from page 42 of "Thinking as Computation" by Hector Levesque. Let's get started with a quick knowledge base. Because of that, I created a quick little program that will demonstrate a simple menu and some I/O. When I started learning Prolog, I thought that the interactive console was great for trying things out and running queries real time, but I noticed an overall lack of instruction out there on writing a menu driven program that will take input. Example Prolog Program An Example Prolog Program Introduction