COMPANY: Monroy & Associates AUTHOR: Jesse Monroy, Jr. CONTACT_INFO: monroyj@yahoo.com VERSION: 1.0 LAST_REVISION: 99/02/14



Beginners Notes to Using Prolog.

This is intended to help those who: 1) know how to program (C, Perl, csh(1), Fortran, Pascal, Basic, Tcl/Tk, Smalltalk). 2) have read prolog literature. 3) have a reading, but not functional, understanding of how prolog works. 4) believe that prolog can help solve a problem. Some basic question arise that are not covered in literature or is not easily found. Specifically I am working with SWI-Prolog, but much of what is written here should help with any prolog. You should also be aware that I am doing this on trial and error basic, so once you've realized enough to get along. Toss this, because I don't want my errors to be your failure. Lastly, this is written as a sequence, you must read #1, to get #2. You must read #2 to get #3. When this sequence breaks down, I'll let you know. Addendum on 99/02/15

The Period.

Before I start, or forget, 'The All Important Period' is not seen in the documentation as much as one might think, but without it Prolog does not know when to start processing things. For C, Perl and Pascal people, this is equivalent to forgeting the semi-colon ';'. For Fortran, csh(1), Basic and Tcl/Tk people this is like not putting an 'End of Line' character at the end of a line. Hmm, odd analogy; perhaps it's more like forgetting to save the program.

How to Stop Prolog (exit the program).

Starting is easy, just envoke the programs executable name (pl) at the command line. Command line options are usually spelled out, but how do you exit a program once it is started, that's a trick. Assuming for a moment you do not want to save a program (that will come later), hit control-c (^C). From this you'll usually get another prompt: ---- Action (h for help) ? ---- Typing an 'h' gets us: ---- a: abort b: break c: continue e: exit g: goals t: trace h (?): help Action (h for help) ? ---- `What does this mean?`, that's my first question. 'e' exits the program immediately 'a' aborts whatever you've type so far 'c' continues where you left off 'h' gets us the 'Action' help menu, again So what does 'g', 't' and 'b' do? I don't know yet, but I suspect: 'g' lists possible goals 't' traces the program, a debugging tool 'b' breaks the current script (whatever your working on) and give a new shell. Is this what it really does? Well when I have a program written and it works, I'll test some of these things and let you know by creating a link here. Otherwise, assume I'm wrong. Lastly, you might wonder if there are any other ways to exit Prolog. Yes, there are, but that is a little later.

After you start the program and how the prompt works and what it means.

When you start the program you typically get something like: ---- Welcome to SWI-Prolog (Version 2.8.6) Copyright (c) 1993-1997 University of Amsterdam. All rights reserved. For help, use ?- help(Topic). or ?- apropos(Word). 1 ?- ---- Here we see three section, the copyright, a message clue for help and the actual prompt. The copyright is very evident, we don't need to say much about it. The message on the second section clues us in on how to get help, and how to search the help data base. That section will be discussed later. The thing we are looking for is the prompt. How does it work?, is the question. ---- 1 ?- ---- There it is (above). What does it mean? The number in the first column tells that this is the first line; kind of a history marker for those of you familiar with csh(1). The second column is blank and the third and fourth have a '?' and '-', respectively. That pair of characters are the prompt. That is, the '?-' is the prompt, signalling the need some input. What kind of input? Perhaps a goal or a new script. Anthing else? At this point, if you hit the (Enter Key or for you Tcl/Tk People) you get a pipe on the next line with the cursor looking at you like you're stupid. The question is `what to do?` answer: hit control-c (^C). From this you will get another prompt ---- Action (h for help) ? ---- We now get the familiar 'Action' prompt. This look like we are going in circles, but the next section will help.

How to get help in Prolog (internal man pages).

Previouly, we noted after the program started we got three sections: the copyright, a message clue for help and the actual prompt. Below we see a clue as to the help in the fourth (4th) line (third (3rd) line if you read in 'C' arrays). ---- Welcome to SWI-Prolog (Version 2.8.6) Copyright (c) 1993-1997 University of Amsterdam. All rights reserved. For help, use ?- help(Topic). or ?- apropos(Word). 1 ?- ---- This line: ---- For help, use ?- help(Topic). or ?- apropos(Word). ---- Gives us a clue, that perhaps we can use 'help' and 'apropos'. Indeed, if we type at the prompt: ---- 1 ?- help(exit). ---- we get: ---- exit(+Label, +Value) Calling exit/2 makes the innermost block which Label unifies exit. The block's ExitValue is unified with Value. If this unification fails the block fails. Yes ---- What this tells us is that 'exit' is a predicate. Namely it says exit/2 is a built-in predicate (function, procedure or module, for Fortran, C and Pascal people). It also gives us help on the predicate and a reponse (on the last line) that Prolog has reach a goal. If you recall, the 'yes' is a response that prolog did reach a conclusion (or goal). Lastly, as for 'exit', we won't delve into that, we'll leave that for another day. However, the question may arised `Will this exit the program?`. answer: no. To answer that question we would want to type 'apropos(exit).' we get: ---- 2 ?- apropos(exit). exit/2 Exit from named block. See block/3 halt/0 Exit from Prolog halt/1 Exit from Prolog with status Yes ---- The response from 'apropos' are three lines about the built-in predicates 'exit' and 'halt'. From here you'll note that halt/0 will allow us to exit the program. Yeah!!! Now you know why the most popular computers have the on/off switch in the front of the computer and it's labeled. You can also try: ---- 3 ?- apropos(help). help/0 Give help on help help/1 Give help on predicates and show parts of manual apropos/1 library(online_help) Show related predicates and m anual sections Section 2-3 "Online Help" Yes ---- AND ---- 4 ?- explain(help). "help" is an atom Referenced from 1-th clause of online_help:help/0 online_help:help/0 is a predicate defined in /usr/home/jessem/bin/prolog/lib/pl-2.8.6/library/help.pl:30 Possibly Referenced from 1-th clause of online_help:help/0 online_help:help/1 is a predicate defined in /usr/home/jessem/bin/prolog/lib/pl-2.8.6/library/help.pl:36 Referenced from 1-th clause of online_help:help/0 Yes ---- From this point on, the section can be read in any order, but I will continue to try to make all the notes read sequentially. Lastly, if you've wondered why no has dones this yet, just note this took almost two (3) hours to write, review, spell check, format, htmlize and notify (email). NOTE: A Webster dictionary http://work.ucsd.edu:5141/cgi-bin/http_webster returns the meaning of apropos as: of an appropriate or pertinent nature

monroyj@yahoo.com

Monroy & Associates Feb 14 1999

.

1