Select this to skip to main content [CSUSB] >> [CNS] >> [Comp Sci Dept] >> [R J Botting] >> [CSci620] >> lab17 [Source]
[Index] [Schedule] [Syllabi] [Text] [Labs] [Projects] [Resources] [Search] [Grading]
Notes: [01] [02] [03] [04] [05] [06] [07] [08] [09] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20]
Tue May 25 07:40:51 PDT 2004

Contents


    CSci620 Programming Languages -- Hello, Prolog!

      Check out New things on the Course Web Page

      [ index.html ]

      Goal

      Learn a little about how Prolog works

      Process

      Running examples and taking notes.

      Work in pairs!

      Deliverable

      Two or three pages of notes on what you have learned. These notes can be on paper or online. The can be put on the web if you want.

      Deadline

      End of lab

      How to use Prolog

      To run tests use the command
       		pl
      if it works. I've installed a link to the SWI Prolog system as
       		/share/bin/pl
      and you may either need to give the full path name
       		/share/bin/pl
      or add /share/bin to your shell PATH.

      To test a Prolog program in a file called forExample.plg use

       		/share/bin/pl forExample.plg
      or
       		/share/bin/pl forExample.plg

      If /share/bin/pl doesn't exist or fails to run you may have to use

       		gprolog
      in its place.

      Version

      We are using 3.3.10 SWI-prolog. I choose this version because it seems to be relatively stable. Check out [ http://www.swi-prolog.org/ ] too see the various versions that are available. I have downloaded the Windows/MSDOS executable and run it on my laptop. Oddly it is the only programming language with this honor!

      The Gnu version of Prolog is similar but some predicates are different and it doesn't seem to work as well on some problems.

      Help in Prolog

      Start up Prolog and try the following queries out...
       		Don't forget the '.' at the end of each query.
       	help.
       	help(1-1).
       	help(2-1).

       	help(=).
       	help(is).
       	help(member).
      The notation name/arity which means: the predicate with functor name and arity arguments. The signs on the arguments in the description say whether they have to be in or out arguments - whether you supply a value or if the predicate will supply the value. Sometimes either can happen as is needed.

      Getting lists of helpful topics on a given subject:

       	apropos(list).
       	apropos(help).

      The Game is afoot!

      This is simple demonstration of the power of Logic Programming. Don't get bogged down in how, just download and run the program.

      Sherlock Holmes is using a computer("The Engine") to investigate the murder at the Metropolitan Club. Read the handout first....

      Find and download(Shift/click, and "Save as" text) a copy of

       	http://www.csci.csusb.edu/dick/cs320/prolog/metro1.plg
      [ metro1.plg ] You can run Prolog with UNIX command
       	pl
      Tell the interpreter to compile the facts of the case into database.
       	consult('metro1.plg').
       	                     ^Don't forget the period.
      You can now investigate the murder. What happens when you input these lines?
       	listing(murderer).
       	listing(room).
       	listing(attire).
       	listing(hair).
      Don't forget the periods, and the case of everything is lower case.

      Then try inputting this query:

       	murderer(X).
      Don't forget the periods, and the case of X.

      We will now ask Prolog to show us, step by step how it solved the crime:

       	trace, murderer(X).
      Keep tapping return as each step is taken. ("creep" is not intended to be insulting... it indicates that the system is taking a very small step forward or backward).

      From the Book

      Try out the examples in the book on pages 195..211.

      Be careful to create the database/rule files before you start to run the Prolog interpreter, see [ 17.html ] for guidance.

      Take notes.

      Work in pairs: one dictate and one type.

      To get credit show me notes and anything odd that happens.

      Hints

      Study these hints if unexpected things happen...

      Default Editor

      If you have a favorite editor and want to have invoked from other UNIX programs (like mail and Prolog) then add these lines to your .profile
       		EDIT=name_of_your_favorite_editor
       		VISUAL=$EDIT
       		EDITOR=$EDIT
       		export EDIT VISUAL EDITOR

      The next time you login most UNIX programs will know what editor you like to use.

    . . . . . . . . . ( end of section CSci620 Programming Languages -- Hello, Prolog!) <<Contents | Index>>

    Glossary

  1. BNF::="Backus-Naur Form", for syntax and grammar, developed by Backus and Naur.
  2. EBNF::="Extended " BNF.
  3. HTML::= "HyperText Markup Language", used on the WWW.
  4. HTML_page::syntax= "<HTML>" head body.
  5. Java::="An " OO " Language from Sun".
  6. LISP::= "LISt Processing Language".
  7. LRM::="Language Reference Manual".
  8. OO::="Object-Oriented".
  9. Prolog::="Programming in Logic".
  10. TBA::="To Be Announced".
  11. UML::="Unified Modeling Language".
  12. URL::=Universal_Resource_Locator,
  13. Universal_Resource_Locator::syntax= protocol ":" location, where
    Net
    1. protocol::= "http" | "ftp" | "mailto" | ... ,
    2. location::= O( "//" host) O(pathname).

    (End of Net)
  14. WWW::= See http://www.csci.csusb.edu/dick/cs620/, index to web site for this class.
  15. XBNF::="eXtreme" BNF, developed by the teacher from EBNF, designed to ASCII input of syntax, semantics, and other formal specifications.


Formulae and Definitions in Alphabetical Order