home *** CD-ROM | disk | FTP | other *** search
/ Turbo Toolbox / Turbo_Toolbox.iso / sharew / pdpro / prolog.doc < prev   
Encoding:
Text File  |  1985-11-07  |  74.3 KB  |  2,641 lines

  1.  
  2.          
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28.                      A.D.A PROLOG Documentation Version 1.7k
  29.                   for the Educational and Public Domain Versions
  30.  
  31.                                   November 11, 1985
  32.  
  33.               Copyright Robert Morein and Automata Design Associates
  34.  
  35.                                  1570 Arran Way
  36.                                Dresher, Pa. 19025
  37.  
  38.                                  (215)-646-4894
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.                                       News
  69.  
  70.              Release  1.7k  fixes  some  bugs  in  the  "cut"  and  "not" 
  71.         operators. ANYONE who has ever purchased a copy of any version of 
  72.         A.D.A.  PROLOG is entitled to a no-charge update.  Simply send us 
  73.         your original disk or a photocopy of the receipt. 
  74.  
  75.         We   have   included  in  pre-release  form   Simon   Blackwell's 
  76.         expert system shell. This system is tailored to A.D.A. PROLOG and 
  77.         includes forward and backward chaining,  and a linkage method  of 
  78.         insuring database consistency.  Bayesian reasoning, rule editing, 
  79.         and documentation are forthcoming.
  80.  
  81.         (11/08/85)  Simon  has  just told me that there is a bug  in  the 
  82.         forward chaining part of the system. He's already fixed  the bug, 
  83.         and it will appear on the next disk.
  84.  
  85.         The  system was developed on VML PROLOG,  but it is our intention 
  86.         to expeditiously insure that it runs under PD PROLOG as well.  To 
  87.         that end,  we have added I/O redirection, since that is how Simon 
  88.         stores things to disk.
  89.  
  90.  
  91.  
  92.                                 Copyright Notice
  93.  
  94.  
  95.  
  96.              The  public domain PD PROLOG system has been contributed  to 
  97.         the  public domain for unrestricted use with one  exception:  the 
  98.         object  code  may not be  disassembled  or  modified.  Electronic 
  99.         bulletin  boards  and SIG groups are urged to aid in giving  this 
  100.         software the widest possible distribution.
  101.  
  102.              This documentation may be reproduced freely,  but it may not 
  103.         be  included in any other documentation without the permission of 
  104.         the author.
  105.  
  106.          
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.                                   Introduction
  135.                 
  136.         We  are pleased to present the third major version of PD  PROLOG, 
  137.         version 1.7.  Version 1.7 continues to refine "problems" and adds 
  138.         the  entertaining  feature of IBM PC video  screen  support.  The 
  139.         memory requirements are somewhat greater than the original, since 
  140.         it   is  uses  the  large  memory  model.   It   compensates   in 
  141.         thoroughness.  The memory requirement is about 210K bytes of TPA, 
  142.         and it will benefit from up to 253k bytes. The availalble 
  143.         workspace is 100K bytes.
  144.  
  145.         We  hope  that you'll get some fun out of this  PROLOG.  It  will 
  146.         afford  you exposure to THE fifth generation language at the cost 
  147.         only  of  some  intellectual  effort.  The  motive  is  perfectly 
  148.         explicable:  We  want you to think of Automata Design  Associates 
  149.         for  fifth  generation  software.  It also gives us a  nice  warm 
  150.         feeling.
  151.  
  152.         The memory requirement is 200 k of transient program  area,  plus 
  153.         whatever  space is needed to execute programs from within PROLOG. 
  154.         DOS or MSDOS 2.0 are required.  The program does not require  IBM 
  155.         PC  compatibility to run,  although the screen access routines do 
  156.         require compatibility.
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.                      Products by Automata Design Associates
  201.  
  202.              Automata  Design  Associates  specializes  in  software  for 
  203.         artificial  intelligence  and  robotic  applications.   A  PROLOG 
  204.         language  system is available in various configurations.  A  LISP  
  205.         interpreter will be introduced in March of 1985.
  206.  
  207.  
  208.              There  are five versions of PROLOG available  from  Automata 
  209.         Design  Associates.  All  of  them run under the MSDOS  or  PCDOS 
  210.         operating systems. Other environments will be supported soon.
  211.  
  212.  
  213.              .Public Domain PROLOG
  214.  
  215.         This  serves to further the general awareness of the public about 
  216.         PROLOG.  It  also is an excellent adjunct to anyone learning  the 
  217.         language.  Most  of  the core PROLOG described  by  Clocksin  and 
  218.         Mellish  in  the book Programming In  PROLOG  is  implemented.  A 
  219.         complete  IBM PC video screen support library is included in this 
  220.         and  all other A.D.A.  prologs.  Trace predicates are  not.  This 
  221.         version is available from us for $10.00 postage paid.
  222.  
  223.  
  224.              .Educational PROLOG
  225.  
  226.         At  extremely modest cost this affords an educational institution 
  227.         or  individual  a  PROLOG  system  which  provides  the   maximum 
  228.         available  programming  area  available  within  the  8086  small 
  229.         programming model.  Tracing,  a debugging aid,  allows monitoring 
  230.         a program as it runs.  User settable spy points selectively allow 
  231.         this.  Exhaustive  tracing  is also  available.  I/O  redirection 
  232.         gives some file ability.
  233.  
  234.              An  "exec"  function allows the execution of  a  program  or 
  235.         editor  from  within  PROLOG,  thus  encouraging  an  interactive 
  236.         environment.
  237.  
  238.              An  "interrupt"   menu is added,  permitting the control  of 
  239.         tracing, toggling the printer, and screen printing.
  240.  
  241.              Definite clause grammar support is now included.
  242.              
  243.              The cost of Educational PROLOG is $29.95.
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.              .FSM PROLOG
  267.  
  268.              A  small  increment  in price adds full random  access  file 
  269.         capability. Character and structure I/O are allowed.
  270.  
  271.              The  "asserta and "assertz" predicates are expanded and work 
  272.         with a clause indexing ability.  One can assert clauses  anywhere 
  273.         in the database under precise pattern matching control. 
  274.  
  275.              A tree structured lexical scoping system and floating  point 
  276.         arithmetic are other enhancements.
  277.  
  278.              The cost of FSM PROLOG is $49.95
  279.  
  280.  
  281.  
  282.              .VMI PROLOG -- Virtual Memory (Replaces type VMS)
  283.  
  284.  
  285.              At reasonable cost the addition of virtual memory gives  an 
  286.         expansion of capabilities of an order of magnitude. 
  287.  
  288.              The  database on disk is treated transparently.  No  special 
  289.         provisions  need  be  made  by the  user.  Virtual  and  resident 
  290.         databases  may be mixed.  A unique updating algorithim  preserves 
  291.         the format of the database as typed by the user while making only 
  292.         those changes necessary to make it equivalent to the database  in 
  293.         central memory.
  294.  
  295.              The cost of VMI PROLOG is $99.95
  296.  
  297.  
  298.  
  299.  
  300.  
  301.  
  302.  
  303.  
  304.  
  305.  
  306.  
  307.  
  308.  
  309.  
  310.  
  311.  
  312.  
  313.  
  314.  
  315.  
  316.  
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.  
  332.              .VML PROLOG Large model Virtual Memory System
  333.  
  334.              A.D.A.  PROLOG is a remarkable fifth generation developement 
  335.         tool  for  the  implementation  of  intelligent  strategies   and 
  336.         optimized  control.  It  is both the kernel for  applications  of 
  337.         virtually  unlimited scope and a sophisticated developement  tool 
  338.         that multiplies the productivity of the programmer many times. 
  339.  
  340.              With  a  cost/performance ratio exceeding that of any  other 
  341.         product  and  a  compatibility  insured  by  compliance  to   the 
  342.         Edinburgh syntax, performance is enhanced by numerous extensions, 
  343.         many of them invisible to the user.
  344.  
  345.              A quick overview of some of the features discloses:
  346.  
  347.              1) Invisible compilation to a semantic network preserves the 
  348.              flexibility  of  the  interpreted mode and the  speed  of  a 
  349.              compiler.
  350.                   The programmer can compile and recompile any portion of 
  351.              a  module at any time.  The edit/compile/test cycle is short 
  352.              and free of strain. An interface is provided to an editor of 
  353.              choice.
  354.  
  355.              2) Floating point arithmetic with a full complement of input 
  356.              and output methods, transcendental and conversion functions.
  357.  
  358.              3)  Virtual memory.  Module size and number is unrestricted. 
  359.              Resident and virtual modules may be coresident.  Compilation 
  360.              is incremental. The cache algorithim is sophisticated.
  361.                   Changes  made in the database can be updated to disk by 
  362.              a single command.
  363.  
  364.              4) A powerful exec function,  and acceptance of stream input 
  365.              make integration into applications practical.
  366.  
  367.              5) Many   additional  built-in  predicates   enhance   the 
  368.              efficiency of the system.
  369.  
  370.              6) Debugging facilities let you see your program run without 
  371.              any additional generation steps.
  372.  
  373.              7)  Totally  invisible and incremental  garbage  collection. 
  374.              There is NEVER any wait for this function.
  375.  
  376.         The  cost  of this system is $200 for the MSDOS version.
  377.  
  378.  
  379.  
  380.  
  381.  
  382.  
  383.  
  384.  
  385.  
  386.  
  387.  
  388.  
  389.  
  390.  
  391.  
  392.  
  393.  
  394.  
  395.  
  396.  
  397.  
  398.                                  Upgrade Policy
  399.  
  400.              Half  the  cost  of any A.D.A.  PROLOG  interpreter  may  be 
  401.         credited to the purchase of a higher level version.
  402.              The  full cost of VMS prolog may be applied to the  purchase 
  403.         of VMI or VML PROLOG.
  404.              Updates  to  a particular level product vary from $15.00  to 
  405.         $35.00.
  406.  
  407.  
  408.                                 Run-time Packages
  409.  
  410.              Software  developers wishing to integrate an A.D.A.  product 
  411.         into  their  system  should inquire  about  specialized  run-time 
  412.         packages available at reasonable cost.
  413.  
  414.  
  415.  
  416.                               Technical Information
  417.  
  418.              Technical information may be obtained at (215) - 646- 4894
  419.  
  420.              Perhaps we can answer the following questions in advance:
  421.  
  422.              There is no support for:  APPLE II, Atari, Commodore, or  
  423.         CPM 80 .  Other machines from these manufactures may be supported 
  424.         in the future.
  425.  
  426.              The MSDOS products are available on 5" and 8" diskettes.
  427.  
  428.  
  429.  
  430.                               To Place Your Order:
  431.  
  432.              You may place your order at the following number:
  433.  
  434.                         (215)-646-4894   - day and night.
  435.  
  436.  
  437.  
  438.                                      Returns
  439.  
  440.              The  software may be returned within 30 days of purchase for 
  441.         a full refund.  This applies whether or not the software has been 
  442.         used.  We do ask that manuals, disks and packaging be returned in 
  443.         excellent condition.
  444.  
  445.  
  446.  
  447.  
  448.  
  449.  
  450.  
  451.  
  452.  
  453.  
  454.  
  455.  
  456.  
  457.  
  458.  
  459.  
  460.  
  461.  
  462.  
  463.  
  464.                       How to run the Demonstration Programs 
  465.                         without Knowing What You're Doing
  466.  
  467.              We strongly advise that you purchase the book Programming in 
  468.         PROLOG by Clocksin and Mellish,  publisher Springer Verlag, 1981. 
  469.         For  the  impatient we give some advice.  Type the  demonstration 
  470.         program you wish to run.  There must be at least one entry  point 
  471.         within  the  program.  
  472.  
  473.         Note:  Please  understand that these are demonstrations programs. 
  474.         Regarding  user  interface,  they are poorly  written.  You  will 
  475.         probably have to read Clocksin and Mellish to appreciate that the 
  476.         following examples of input are not equivalent: "yes." , "yes" .
  477.  
  478.  
  479.         The animals program - "animal"
  480.          
  481.              Most  of the examples require C & M for  comprehension.  The 
  482.         program "animals", however, can be appreciated by anyone. It is a 
  483.         traditional   example of an expert system.
  484.              
  485.              We had hoped to include the animals program on disk,  but we 
  486.         have  found  to  our  dismay that the version which  we  used  is 
  487.         allegedly copyrighted by the implementors of PROLOG 86.  Don't be 
  488.         surprised - even "happy birthday" is copyrighted.  We will simply 
  489.         point out that the November '84 issue of Robotics Age included  a 
  490.         version  of  the  animals game,  which you can,  at the  risk  of 
  491.         copyright infringement,  type in.  There is only one change  that 
  492.         need  be  made.  The "concat" function used in that  program  has 
  493.         arguments of the form:
  494.  
  495.                       concat( [atom1, atom2,...], result ).
  496.  
  497.         In order to make the concat definition more closely resemble that 
  498.         of  "name",  which  is  described by Clocksin  and  Mellish,  the 
  499.         argments have been reversed:
  500.  
  501.                       concat( result, [atom1, atom2,...] )
  502.  
  503.         Assuming  that you have typed in the program and made the  change 
  504.         just noted, the following steps are required to run it:
  505.              
  506.              Run the prolog.exe file.  The prompt "?-" will appear.  Type 
  507.         "consult( 'animals' ).<CR>".  Here <CR> indicates you are to type 
  508.         a  carriage  return.  The PROLOG system will load  "animals"  and 
  509.         compile  it into an internal form.  When the "?-" prompt  appears 
  510.         PROLOG is ready to run the "animals" guessing game. The object of 
  511.         the program is to deduce the animal you are thinking of. To start 
  512.         it  off  type  "help.<CR>".  PROLOG  will  respond  by  asking  a 
  513.         question. 
  514.              Because of the way the animals program is written,  you must 
  515.         respond in a rigid format.  You may type "yes<CR>",  "no<CR>", or 
  516.         "why<CR>". 
  517.              Eventually the program will terminate with either a guess as 
  518.         to what animal you are thinking of,  or a remark that the  animal 
  519.         is  not within its domain of knowledge.  The program has learned, 
  520.         however.  You  may  run  the  program again to  see  what  effect 
  521.         additional knowledge has on the program's behavior. 
  522.  
  523.              The program fragment "console" shows how you may improve the 
  524.  
  525.  
  526.  
  527.  
  528.  
  529.  
  530.         console input routines of any of these programs.
  531.              
  532.  
  533.         The Hematology Diagnosis Program - "hemat"
  534.  
  535.              Although  the  logical structure is not as sophisticated  as 
  536.         that of "animals", it is interesting for several reasons:
  537.  
  538.              1)  The  program  evaluates numerical data to  arrive  at  a 
  539.         diagnosis.
  540.  
  541.              2) Although inaccurate, it demonstrates that useful question 
  542.         answering systems are not difficult to write in PROLOG.
  543.  
  544.              3)  There  are  some mistakes in  the  program,  which  only 
  545.         slightly impede its usefulness. 
  546.  
  547.              This  program  uses  structure  input.  Terminate  all  your 
  548.         answers with a period, as in "y.<CR>", or "no.<CR>".
  549.         The starting point is "signs.<CR>".  PROLOG will prompt  you 
  550.         for  signs  of  anemia.  The  program attempts  to  diagnose  two 
  551.         varieties of a hemolytic anemia.
  552.              The program could use a good working over by a  hematologist 
  553.         and we would be delighted to collaborate.
  554.  
  555.  
  556.         Prime Number Generator - "sieve"
  557.  
  558.              This  program demonstrates that anything can be programed in 
  559.         PROLOG if one tries hard enough.  Asking the  question   
  560.           "primes( 50, L ).<CR>" causes a list of prime numbers less than 
  561.         50  to be printed out.  "Sieve" is heavily recursive and  quickly 
  562.         exhausts the stack space of the small model interpreters.
  563.  
  564.  
  565.         Grrules
  566.  
  567.              This  is  an  example  of the use  of  the  definite  clause 
  568.         grammer  notation.  PD  PROLOG  does not  have  this  translation 
  569.         facility,  but ED PROLOG and  all of our other versions do. It is 
  570.         possible  to  perform  the  translations  by  hand  if  you  have 
  571.         thoroughly  read  C  & M.  Then you would have  the  pleasure  of 
  572.         asking:
  573.  
  574.                  ?-sentence( X, [every,man,loves,a,woman], [] ).
  575.  
  576.         and  having the meaning elucidated as a statment in the predicate 
  577.         calculus.
  578.  
  579.  
  580.  
  581.  
  582.  
  583.  
  584.  
  585.  
  586.  
  587.  
  588.  
  589.  
  590.  
  591.  
  592.  
  593.  
  594.  
  595.  
  596.                                Special Offer  # 1
  597.  
  598.              For  some  inexplicable reason,  demonstration programs  are 
  599.         hard to come by. We are too busy writing PROLOG fill this gap. We 
  600.         will  reward the contribution of "cute" sample programs with  the 
  601.         following:
  602.  
  603.              1) A free  copy of type VMI virtual memory PROLOG
  604.  
  605.              2) The sample program will be published as an intact file 
  606.              together with whatever comments or advertisments the author
  607.              may see fit to include, on our distribution disks. 
  608.  
  609.              3) Exceptional contributions may merit a copy of type VML 
  610.              large  model virtual memory PROLOG which now incorporates  a 
  611.              UNIX1 style tree structured domain system.
  612.  
  613.  
  614.                                 Special Offer # 2
  615.  
  616.  
  617.              If  you are a hardware manufacturer and would like a  PROLOG 
  618.         language  for your system,  the solution is simple.  Just send us 
  619.         one  of  your machines!  Provided your system  implements  a  "C" 
  620.         compiler, it will be ported in no time flat.
  621.  
  622.  
  623.         ______
  624.              1. Trademark of AT & T.
  625.  
  626.  
  627.  
  628.  
  629.  
  630.  
  631.  
  632.  
  633.  
  634.  
  635.  
  636.  
  637.  
  638.  
  639.  
  640.  
  641.  
  642.  
  643.  
  644.  
  645.  
  646.  
  647.  
  648.  
  649.  
  650.  
  651.  
  652.  
  653.  
  654.  
  655.  
  656.  
  657.  
  658.  
  659.  
  660.  
  661.  
  662.                          Writing Programs For ED PROLOG
  663.  
  664.              You do not type in programs at the "?-" prompt.  There is no 
  665.         built-in  editor.  The command "consult( user )" is accepted  but 
  666.         does not cause PROLOG to enter an editing mode.  We feel that the 
  667.         most universally acceptable editing method is for the user to use 
  668.         a text editor of choice,  which can be invoked from within PROLOG 
  669.         by the "exec" predicate.
  670.  
  671.              Use  Wordstar  or your customary editor to write a  program. 
  672.         Then  run  PD  PROLOG and use the consult function  to  load  the 
  673.         program.
  674.  
  675.              In  all  cases except PD PROLOG,  you can  run  your  editor 
  676.         without leaving PROLOG by use of the "exec" predicate.
  677.  
  678.  
  679.  
  680.                              Running the Interpreter
  681.  
  682.         COMMANDS: Give commands in lower case.
  683.  
  684.         TO RUN:
  685.              Invoke PROLOG.EXE. After the "?-" prompt appears,
  686.                type "consult( <filename><CR> )", where <filename> is the 
  687.                desired database.
  688.              To exit, type "exitsys.<CR>"
  689.  
  690.         TO ASK A QUESTION:
  691.              At the prompt, type "<expression>.<CR>", where 
  692.              <expression>  is  a  question as described by  Clocksin  and 
  693.              Mellish. Be sure to terminate the question with a period.
  694.              The question may be up to 500 characters long.
  695.  
  696.         TO INPUT A STRUCTURE AT THE KEYBOARD:
  697.              The structure may be up to 500 characters in length. Be sure 
  698.              to terminate with a period.
  699.  
  700.         TO ASK FOR ANOTHER SOLUTION:
  701.              If a solution has been provided, the PROLOG interpreter will 
  702.              ask  "More?  (Y/N):".  Only  if  a "y"  is  typed  will  the 
  703.              interpreter perform a search.
  704.  
  705.         TO ABORT A SEARCH:
  706.              Simply   type   the  escape  key.   The   interpreter   will      
  707.              respond  with  "Interrrupted.",  and return to  the  command      
  708.              prompt.
  709.  
  710.         TO LOAD ANOTHER DATABASE:
  711.              Type  "consult(<filename>).<CR>" The file name must have the 
  712.              extension  ".PRO".  It  is  not  necessary  to  include  the 
  713.              extension in the argument of consult. The file name as given 
  714.              must not be the same as a predicate name in the file or  any 
  715.              file which will be loaded.
  716.  
  717.         TO TRACE:
  718.              When the system displays the prompt "?-", type "trace.<CR>".  
  719.              The display will likely move too rapidly for you to read. To 
  720.              stop the display,  type Control S.  To restart the  display, 
  721.              type  Control S.  To turn the trace      display  off,  type 
  722.  
  723.  
  724.  
  725.  
  726.  
  727.  
  728.              "notrace<CR>"  at  the  prompt  "?-".   The  interrupt  menu 
  729.              contains  additional  options,  such  as sending  all  trace 
  730.              output to a file, as well as display at the console.
  731.  
  732.         TO INTERRUPT A PROGRAM:
  733.              See  the  section  entitled  "The  Interrupt  Menu"  for   a 
  734.              description  of the flexible options.  Basically,  one types 
  735.              ESC  to terminate a program,  while Control V or  Control  I 
  736.              interrupt a program. 
  737.  
  738.         TO REMOVE A DATABASE:
  739.              Type "forget(<filename>).<CR>"
  740.  
  741.         TO EXIT TO THE OPERATING SYSTEM:
  742.              Type "exitsys.<CR>"
  743.  
  744.              The system is totally interactive; any commands the operator 
  745.         gives  are and must be valid program statements.  Statements must 
  746.         terminate with a period.      All commands which take a file name 
  747.         also  accept a path name.  Any name which is not a  valid  PROLOG 
  748.         atom (refer to C & M) must be enclosed in single quotes. Thus one 
  749.         could say
  750.  
  751.              consult( expert )
  752.  
  753.         but one would need single quotes with
  754.  
  755.              consult( 'b:\samples\subtype\expert' ).
  756.  
  757.  
  758.         To exit the system, type "exitsys.<CR>"
  759.  
  760.         Atoms  may contain MSDOS pathnames if they are enclosed by single 
  761.         quotes, ie.,  '\b:\samples\animal' .
  762.  
  763.         You may consult more than one file at a time.  However, all names 
  764.         are public and name conflicts must be avoided. The order in which 
  765.         modules are loaded may,  in cases of poor program design,  affect 
  766.         the behavior.
  767.  
  768.  
  769.  
  770.                              Command Line Arguments
  771.  
  772.              ED  PROLOG accepts one command line argument,  which is  the 
  773.         name  of  a "stream" which replaces the console  for  input.  The 
  774.         "stream"  in  MSDOS is a pipe or file which supplies input  until 
  775.         end-of-file is reached. Control then reverts back to the console. 
  776.         To avoid noisy parser error messages when end-of-file is reached, 
  777.         the last command in the file should be "see( user )."
  778.  
  779.  
  780.  
  781.                                A Reference of Note
  782.  
  783.  
  784.              With  minor  exceptions,  the syntax is a superset  of  that 
  785.         described  by  Clocksin and Mellish in the  book  Programming  in 
  786.         Prolog by W.F.  Clocksin and C.S.  Mellish, published by Springer 
  787.         Verlag in Berlin, Heidelberg, New York, and Tokyo. We shall refer 
  788.  
  789.  
  790.  
  791.  
  792.  
  793.  
  794.         to this book as "C & M".
  795.  
  796.  
  797.              There   are  very  few   syntactical   differences,   mostly 
  798.         unrecognized and/or minor.
  799.              When  an operator is declared using the "op" statement,  the 
  800.         operator must be enclosed in single quotes in the "op"  statement 
  801.         itself,  if  it would not otherwise be a legal Edinburgh functor. 
  802.         Subsequently,  however,  the parser will recognize it for what it 
  803.         is,  except  in  the "unop" statement,  where it  must  again  be 
  804.         enclosed in single quotes.
  805.  
  806.              Variable numbers of functor paramaters are supported.
  807.  
  808.              A  goal  may be represented by a  variable,  which  is  less 
  809.         restrictive  than  the  C  &  M requirement  that  all  goals  be 
  810.         functors.  The  variable must be instantiated to a  functor  when 
  811.         that goal is pursued.
  812.  
  813.              Rules which appear inside other expressions must be enclosed 
  814.         in  parenthesis  if  the "," operator is to be  recognized  as  a 
  815.         logical connective.
  816.  
  817.              All  infix  operators described by C & M,  and user  defined 
  818.         infix,  prefix, and postfix operators with variable associativity 
  819.         and precedence are supported exactly as in C & M.
  820.  
  821.  
  822.  
  823.  
  824.  
  825.  
  826.  
  827.  
  828.  
  829.  
  830.  
  831.  
  832.  
  833.  
  834.  
  835.  
  836.  
  837.  
  838.  
  839.  
  840.  
  841.  
  842.  
  843.  
  844.  
  845.  
  846.  
  847.  
  848.  
  849.  
  850.  
  851.  
  852.  
  853.  
  854.  
  855.  
  856.  
  857.  
  858.  
  859.  
  860.                          The Built In Predicate Library
  861.  
  862.                         Available Operators in PD and ED PROLOG
  863.  
  864.  
  865.         Column 1 gives the function symbol. 
  866.  
  867.         Column 2 gives the precedence. The range of precedence is 1 to 255.
  868.         A zero in the precedence column indicates the symbol is parsed as 
  869.         a functor, and precedence is meaningless in this case.
  870.  
  871.         Column 3 gives the associativity. 
  872.         A zero in the associativity column indicates the symbol is parsed
  873.         as a functor, and associativity is meaningless in this case.
  874.  
  875.         Column 4 indicates which version the function is available in. 
  876.         Unless otherwise noted, the function is available in all versions.
  877.         Nonstandard predicates are indicated by "NS".
  878.  
  879.  
  880.         op/pred      precedence    associativity         availability
  881.  
  882.         "!"             0             0
  883.         "|"             0             0
  884.         "="             40,           XFX                   
  885.         "=="            40,           XFX                   
  886.         "\\="           40,           XFX                   
  887.         "\\=="          40,           XFX       
  888.         "/"             21,           YFX       
  889.         "@="            40,           XFX       
  890.         ">="            40,           XFX       
  891.         "=<"            40,           XFX       
  892.         ">"             40,           XFX       
  893.         "<"             40,           XFX       
  894.         "-"             31,           YFX        
  895.         "*"             21,           YFX
  896.         "+"             31,           YFX
  897.         "=.."           40,           XFX
  898.         "-->"           255,          YFY       (not  in  PD PROLOG)
  899.         "?-"            255,          FY  
  900.               
  901.  
  902.  
  903.         "arg"           0,            0,                                   
  904.         "asserta"       0,            0,                                   
  905.         "assertz"       0,            0,                                   
  906.         "atom"          0,            0,                                   
  907.         "atomic"        0,            0,                                   
  908.         "clause"        0,            0,                                   
  909.         "clearops"      0,            0,                                   
  910.         "cls"           0,            0,       NS
  911.         "concat"        0,            0,                                   
  912.         "consult"       8,            FX,                                  
  913.         "crtgmode"      0,            0,       NS
  914.         "crtset"        0,            0,       NS
  915.         "curset"        0,            0,       NS
  916.         "curwh"         0,            0,       NS
  917.         "debugging      0,            0,                                   
  918.         "dir"           0,            0,                                   
  919.         "display"       0,            0,                                   
  920.  
  921.  
  922.  
  923.  
  924.  
  925.  
  926.         "dotcolor"      0,            0,       NS
  927.         "drawchar"      0,            0,       NS
  928.         "drawdot"       0,            0,       NS
  929.         "drawline"      0,            0,       NS
  930.         "exec"          0,            0,                                   
  931.         "exitsys"       0,            0,       NS                          
  932.         "forget"        0,            0,       NS                          
  933.         "functor"       0,            0,                                   
  934.         "get0"          8,            FX,                                  
  935.         "integer"       0,            0,                                   
  936.         "is"            40,           XFX,                                 
  937.         "listing"       0,            0,                                   
  938.         "mod"           11,           XFX,                                 
  939.         "name"          0,            0,                                   
  940.         "nl"            0,            0,                                   
  941.         "nodebug"       0,            0,       (not in PD PROLOG)
  942.         "nonvar"        0,            0,                                   
  943.         "nospy"         50,           FX,      (not in PD PROLOG)
  944.         "not"           60            FX                                   
  945.         "notrace"       0,            0,       (not in PD PROLOG)
  946.         "op"            0,            0,                                   
  947.         "popoff"        0,            0,       NS
  948.         "popoffd"       0,            0,       NS
  949.         "popon"         0,            0,       NS
  950.         "popond"        0,            0,       NS
  951.         "print"         0,            0,                                   
  952.         "prtscr"        0,            0,       NS
  953.         "put"           0,            0,                                   
  954.         "ratom"         0,            0,                                   
  955.         "read"          0,            0,                                   
  956.         "recon"         0,            0, (Note: this is "reconsult")
  957.         "repeat"        0,            0,                                   
  958.         "retract"       0,            0                                    
  959.         "rnum"          0,            0,                                   
  960.         "see"           0,            0,       (not in PD PROLOG)
  961.         "seeing"        0,            0,       (not in PD PROLOG)
  962.         "seen"          0,            0,       (not in PD PROLOG)
  963.         "skip"          0,            0,       (not in PD PROLOG)
  964.         "spy"           50,           FX,      (not in PD PROLOG)
  965.         "tab"           0,            0,                                   
  966.         "tell"          0,            0,       (not in PD PROLOG)
  967.         "telling"       0,            0,       (not in PD PROLOG)
  968.         "told"          0,            0,       (not in PD PROLOG)
  969.         "trace"         0,            0,       (not in PD PROLOG)
  970.         "true"          0,            0,                                   
  971.         "unop"          0,            0,                                   
  972.         "var"           0,            0,                                   
  973.         "write"         0,            0,                                   
  974.  
  975.  
  976.  
  977.  
  978.  
  979.  
  980.  
  981.  
  982.  
  983.  
  984.  
  985.  
  986.  
  987.  
  988.  
  989.  
  990.  
  991.  
  992.                         Description of the Modifications.
  993.              
  994.  
  995.         call( <goal> )
  996.  
  997.              The  predicate as defined in C & M is obsolete.  The purpose 
  998.         was  to permit a goal search where the goal name was  a  variable 
  999.         instantiated  to  some functor name.  A.D.A.  permits writing  of 
  1000.         goals with such names,  so the mediation of the "call" clause  is 
  1001.         no longer necessary.
  1002.  
  1003.              The  "call"  predicate  may  be  trivially  implemented  for 
  1004.         compatibility with the PROLOG definition
  1005.  
  1006.                                  call( X ) :- X.
  1007.  
  1008.  
  1009.  
  1010.         clause
  1011.  
  1012.              The  function  clause(  X,  Y ) has the  new  optional  form 
  1013.         clause(  X,  Y,  I  ).  If the third variable is written,  it  is 
  1014.         instantiated  to the current address of a clause in  memory.  The 
  1015.         only  use of the result is with succeeding assertfa and  assertfz 
  1016.         statements.
  1017.  
  1018.  
  1019.         debugging
  1020.  
  1021.              "Debugging"  prints a list of the current  spypoints.  After 
  1022.         each name a sequence of numbers may appear, indicating the number 
  1023.         of  arguments that is a condition of the trace.  The  word  "all" 
  1024.         appears  if  the  number of arguments is not a condition  of  the 
  1025.         trace.
  1026.  
  1027.         op( <prec>, <assoc>, <functor> )
  1028.  
  1029.              Defines  the  user  definable  grammar  of  a  functor.  The 
  1030.         definition conforms to that in C & M. We mention here a minor but 
  1031.         important point.  If <functor> is not a valid PROLOG atom it must 
  1032.         be   enclosed  in  single  quotes  when  declared  in  the   "op" 
  1033.         declaration.  It  is  not necessary or legal to do this when  the 
  1034.         functor is actually being used as an operator.  In version 1.6, a 
  1035.         declared  or built-in operator can be used either as an  operator 
  1036.         or as a functor. For example, 
  1037.  
  1038.                                  +(2,3) = 2 + 3.
  1039.  
  1040.         is a true statement.
  1041.  
  1042.              Declared  operators  are annotated in the directory  display 
  1043.         with their precedence and associativity.
  1044.  
  1045.  
  1046.  
  1047.  
  1048.  
  1049.  
  1050.  
  1051.  
  1052.  
  1053.  
  1054.  
  1055.  
  1056.  
  1057.  
  1058.         Output predicates
  1059.  
  1060.            display
  1061.            write
  1062.            print
  1063.            put
  1064.  
  1065.              These  functions  have  been  modified  to  accept  multiple 
  1066.         arguments in the form:
  1067.  
  1068.                        print( <arg1>, <arg2>, <arg3>,... )
  1069.  
  1070.         Thus, "put( a, b, c )" would result in the display of "abc".
  1071.              The  names  of  some  PROLOG atoms that may  occur  are  not 
  1072.         accepted  by  the  PROLOG scanner  unless  surrounded  by  single 
  1073.         quotes.  This only applies when such an atom is read in, not when 
  1074.         it is internally generated. Nevertheless, this presents us with a 
  1075.         problem:  We  would  like to be capable of writing  valid  PROLOG 
  1076.         terms to a file. In some cases, it is necessary to add the single 
  1077.         quotes.  In other cases,  such as human oriented output, they are 
  1078.         an irritant. The modified definitions of the following predicates 
  1079.         are an attempt at a solution:
  1080.  
  1081.              display
  1082.              Operator  precedence  is ignored,  all functors are  printed 
  1083.              prefix and single quotes are printed if needed or they  were 
  1084.              supplied if and when the atom was originally input.
  1085.  
  1086.              write
  1087.              Operator  precedence is taken into account and operators are 
  1088.              printed according to precedence.  Single quotes are  printed 
  1089.              under the same conditions as for "display."
  1090.  
  1091.              print
  1092.              Operator  precedence is taken into account and operators are 
  1093.              printed  according to precedence.  Single quotes  are  never 
  1094.              displayed.  This  is  a  human oriented form of  output  and 
  1095.              should  never  be used for writing of terms for  the  PROLOG 
  1096.              scanner.
  1097.  
  1098.  
  1099.  
  1100.  
  1101.  
  1102.  
  1103.  
  1104.  
  1105.  
  1106.  
  1107.  
  1108.  
  1109.  
  1110.  
  1111.  
  1112.  
  1113.  
  1114.  
  1115.  
  1116.  
  1117.  
  1118.  
  1119.  
  1120.  
  1121.  
  1122.  
  1123.  
  1124.         get0
  1125.         read
  1126.  
  1127.              The  functions  "get0"  and "read"  have  been  extended  to 
  1128.         support input from a stream other than the one currently selected 
  1129.         by "see". To direct output to a file or other stream, an optional 
  1130.         argument  is used.  For example,  "get0( char,  <file name> )" or 
  1131.         "get0( char,  user )" would cause input to come from <file  name> 
  1132.         or the console.  If the file has not already been opened,  "get0" 
  1133.         will fail.
  1134.  
  1135.  
  1136.  
  1137.              Atoms enclosed by single quotest, eg. '\nthis is a new line' 
  1138.         can contain the escape sequences
  1139.  
  1140.              '\n', '\r', '\t' and '\''.
  1141.  
  1142.              If these atoms are printed by "display" or "write" they  are 
  1143.         printed  just  as they are.  If they are printed by  the  "print" 
  1144.         clause they are translated as follows:
  1145.  
  1146.         '\n'  results  in  the printing of a carriage return and  a  line 
  1147.         feed.
  1148.         '\r' results in the printing of a carriage return only.
  1149.         '\t' results in the printing of a tab character.
  1150.         '\'' allows the printing of a single quote within a quoted atom.
  1151.  
  1152.              The "portray" feature is not presently implemented.
  1153.  
  1154.  
  1155.  
  1156.  
  1157.  
  1158.  
  1159.  
  1160.  
  1161.  
  1162.  
  1163.  
  1164.  
  1165.  
  1166.  
  1167.  
  1168.  
  1169.  
  1170.  
  1171.  
  1172.  
  1173.  
  1174.  
  1175.  
  1176.  
  1177.  
  1178.  
  1179.  
  1180.  
  1181.  
  1182.  
  1183.  
  1184.  
  1185.  
  1186.  
  1187.  
  1188.  
  1189.  
  1190.                         Description of the New Predicates
  1191.  
  1192.  
  1193.         clearops-
  1194.              Nullify  the  operator  status  of  every  operator  in  the 
  1195.              database.
  1196.  
  1197.         concat( (<variable> | <functor>), <List> )
  1198.              A  list  of functors or operators is concatenated  into  one 
  1199.         string,  which becomes the name of a new atom to which <variable> 
  1200.         or <functor> must match or be instantiated.
  1201.  
  1202.  
  1203.         dir( option )
  1204.              Provide  an  alphabetized listing to the console  of  atoms, 
  1205.         constants,   or   open  files.   Without  options,   simply  type 
  1206.         "dir.<CR>". Options are:
  1207.  
  1208.              dir( pred ) - list clause names only.
  1209.              dir( files ) - list open files only.
  1210.  
  1211.  
  1212.         exitsys
  1213.              Exit to the operating system.
  1214.  
  1215.         forget( <file name> )
  1216.              Make  a database unavailable for use and reclaim the storage 
  1217.         it occupied.
  1218.  
  1219.  
  1220.         ratom( <arg>, <stream> )-
  1221.              Read an atom from the input stream,  to which <arg>  matches 
  1222.         or  is  instantiated.  <stream> is optional.  If <stream> is  not 
  1223.         given, the input stream defaults to the standar input.
  1224.              Input is terminated by a CR or LF, which are not included in 
  1225.         the stream.
  1226.  
  1227.  
  1228.  
  1229.  
  1230.  
  1231.  
  1232.  
  1233.  
  1234.  
  1235.  
  1236.  
  1237.  
  1238.  
  1239.  
  1240.  
  1241.  
  1242.  
  1243.  
  1244.  
  1245.  
  1246.  
  1247.  
  1248.  
  1249.  
  1250.  
  1251.  
  1252.  
  1253.  
  1254.  
  1255.  
  1256.                              Arithmetic Capabilities
  1257.  
  1258.              Integer  arithmetic is supported.  Numbers are 32 bit signed 
  1259.         quantities. The following arithmetic operators are supported:
  1260.  
  1261.                       "+", "-", "*", "/", <, <=, >, >=, mod.
  1262.  
  1263.         Arithmetic operators must never be used as goals,  although  they 
  1264.         may be part of structures. It is legal to write:
  1265.  
  1266.                                     X = a + b
  1267.              
  1268.         which  results in the instantiation of X to the struture (a + b). 
  1269.         But the following is not legal:
  1270.  
  1271.                        alpha( X, Y ) :- X + Y, beta( Y ).
  1272.  
  1273.  
  1274.         Evaluation  of  an arithemtic expression is mediated by the  "is" 
  1275.         and inequality predicates.  For instance,  the following would be 
  1276.         correct:
  1277.  
  1278.                          alpha( X, Y, Z ) :- Z is X + Y.
  1279.  
  1280.                          beta( X, Y ) :- X + 2 < Y + 3.
  1281.  
  1282.  
  1283.  
  1284.  
  1285.  
  1286.  
  1287.  
  1288.  
  1289.  
  1290.  
  1291.  
  1292.  
  1293.  
  1294.  
  1295.  
  1296.  
  1297.  
  1298.  
  1299.  
  1300.  
  1301.  
  1302.  
  1303.  
  1304.  
  1305.  
  1306.  
  1307.  
  1308.  
  1309.  
  1310.  
  1311.  
  1312.  
  1313.  
  1314.  
  1315.  
  1316.  
  1317.  
  1318.  
  1319.  
  1320.  
  1321.  
  1322.                          IBM PC Video Display Predicates
  1323.  
  1324.  
  1325.         A high level method is provided for drawing and displaying on the 
  1326.         screen of IBM PC and compatible computers. 
  1327.  
  1328.  
  1329.  
  1330.         cls
  1331.  
  1332.         Clear  the screen and position the cursor at the upper left  hand 
  1333.         corner.
  1334.  
  1335.  
  1336.  
  1337.         crtgmode( X )
  1338.  
  1339.         Matches  the  argument to the mode byte of the display  which  is 
  1340.         defined as follows:
  1341.  
  1342.                   mode           meaning
  1343.  
  1344.                    0             40 x  25  BW (default)
  1345.                    1             40 x  25  COLOR
  1346.                    2             80 x  25  BW
  1347.                    3             80 x  25  COLOR
  1348.                    4            320 x 200  COLOR
  1349.                    5            320 x 200  BW
  1350.                    6            640 x 200  BW
  1351.                    7             80 x  25  monochrome  display card
  1352.  
  1353.  
  1354.  
  1355.         crtset( X )
  1356.          
  1357.         This  sets the mode of the display.  The argument must be one  of 
  1358.         the modes given above. 
  1359.  
  1360.  
  1361.  
  1362.         curset( <row>, <column>, <page> )
  1363.  
  1364.         Sets the cursor to the given row, column, and page. The arguments 
  1365.         must be integers.
  1366.  
  1367.  
  1368.  
  1369.         curwh(  <row>, <column> )
  1370.  
  1371.         Reports the current position of the cursor.  The argument must be 
  1372.         an integer or variable. The format is:
  1373.  
  1374.              1) page zero is assumed.
  1375.              2) The row is in the range 0 to 79, left to right.
  1376.              3) The column is in the range 0 to 24, bottom to top.
  1377.         dotcolor( <row>, <column>, <color> )
  1378.  
  1379.         The  argument  <color> is matched to the color of  the  specified 
  1380.         dot. The monitor must be in graphics mode.
  1381.  
  1382.  
  1383.  
  1384.  
  1385.  
  1386.  
  1387.  
  1388.  
  1389.  
  1390.         drawchar( <character>, <attribute> )
  1391.  
  1392.         Put a character at the current cursor position with the specified 
  1393.         attribute.  The  arguments  <character> and <attribute>  must  be 
  1394.         integers.  Consult  the IBM technical reference manual  regarding 
  1395.         attributes.
  1396.  
  1397.  
  1398.  
  1399.         drawdot( <row>, <column>, <color> )
  1400.  
  1401.         Put  a dot at the specified position.  The monitor must be in the 
  1402.         graphics  mode.  The  arguments  must be  integer.  The  argument 
  1403.         <color> is mapped to integers by default in the following manner:
  1404.  
  1405.  
  1406.  
  1407.         drawline( <X1>, <Y1>, <X2>, <Y2>, <color> )
  1408.  
  1409.         Draw a line on the between the coordinate pairs. The monitor must 
  1410.         be in the graphics mode and the arguments are integer.
  1411.  
  1412.  
  1413.  
  1414.         prtscr
  1415.  
  1416.         Print  the  screen  as it currently appears.  Be  sure  that  the 
  1417.         printer  is  on  line and ready before invoking  this  predicate, 
  1418.         since otherwise, the system may lock up or abort.
  1419.  
  1420.  
  1421.  
  1422.         The  integer argument <color> referred to in the above predicates 
  1423.         is represented as follows:
  1424.  
  1425.              COLOR          PALETTE 0           PALETTE 1
  1426.              
  1427.                0            background          background
  1428.                1            green               cyan
  1429.                2            red                 magenta
  1430.                3            brown               white
  1431.  
  1432.         To change the palette and the background,  see the IBM  Technical 
  1433.         Reference Bios listings for more information.
  1434.  
  1435.  
  1436.  
  1437.  
  1438.  
  1439.  
  1440.  
  1441.  
  1442.  
  1443.  
  1444.  
  1445.  
  1446.  
  1447.  
  1448.  
  1449.  
  1450.  
  1451.  
  1452.  
  1453.  
  1454.                                    Trace Files
  1455.  
  1456.                                  (type ED only)
  1457.  
  1458.              You  can  now dump your trace to disk,  instead  of  (groan) 
  1459.         wasting  reams of printer paper.  This option is described in the 
  1460.         next section.
  1461.  
  1462.  
  1463.                                The Interrupt Menu
  1464.  
  1465.                                  (type ED only)
  1466.  
  1467.              This  menu  has been modified.  It was formerly  called  the 
  1468.         ESCAPE   menu,  but  the  meaning  of the  ESCAPE  key  has  been 
  1469.         redefined.  It  is  no  longer necessary to display the  menu  to 
  1470.         perform  one of the menu functions.  This reduces the  amount  of 
  1471.         display which is lost by scrolling off the screen.
  1472.  
  1473.              At any time while searching, printing, or accepting keyboard 
  1474.         input,  you can break to this menu.  It is generally not possible 
  1475.         to  do  this  during disk access,  since control  passes  to  the 
  1476.         operating  system  at this time.  Two keys cause  this  break  to 
  1477.         occur:
  1478.  
  1479.              ^V:  The menu is displayed and a command is accepted at the 
  1480.                   prompt  "INTERRUPT>".  After  a command,  the  menu  is 
  1481.                   redisplayed  until  the user selects  a  command  which 
  1482.                   causes an exit. 
  1483.  
  1484.              ^I:  The menu is not displayed.  Command is accepted at the 
  1485.                   prompt  "INTERRUPT>" until the user selects  a  command 
  1486.                   which causes an exit.
  1487.  
  1488.              ESC: Typing this key  causes a  termination of  the  PROLOG      
  1489.                   search  and  control returns to the user command  level      
  1490.                   with a prompt of "?-".  Notice that previously, the ESC      
  1491.                   key invoked this menu. 
  1492.  
  1493.  
  1494.  
  1495.  
  1496.  
  1497.  
  1498.  
  1499.  
  1500.  
  1501.  
  1502.  
  1503.  
  1504.  
  1505.  
  1506.  
  1507.  
  1508.  
  1509.  
  1510.  
  1511.  
  1512.  
  1513.  
  1514.  
  1515.  
  1516.  
  1517.  
  1518.  
  1519.  
  1520.              As the resulting menu indicates, the following functions are 
  1521.         possible:
  1522.  
  1523.              A: Abort the search and return to the prompt.
  1524.  
  1525.              O  Open  a trace file.  The user is prompted for  the  file 
  1526.                 name.  The file receives all trace output.  If a file is 
  1527.                 already opened it is closed with all output preserved.
  1528.  
  1529.              C  Close the trace file if one is open.  Otherwise there is 
  1530.                 no effect.
  1531.  
  1532.             ^C: Immediately  exit PROLOG without closing files.  This is 
  1533.                 not advised.
  1534.  
  1535.             ^P: Typing <Control>P toggles the printer. If the printer is 
  1536.                 on,  all  input  and output will also be  routed  to  the 
  1537.                 printer.
  1538.  
  1539.              S: If  the machine in use is an IBM PC compatible  machine, 
  1540.                 the  currently displayed screen will be printed.  If  the 
  1541.                 machine  is  not an IBM PC compatible,  do not  use  this 
  1542.                 function.
  1543.  
  1544.              T: If  trace  is in use,  most of the trace output  can  be 
  1545.                 temporarily turned off by use of this function,  which is 
  1546.                 a toggle.
  1547.  
  1548.              R:  Entering  another  ESC causes a return to the  current 
  1549.                 activity  (keyboard  input or search)  with  no  residual 
  1550.                 effect from the interruption.
  1551.  
  1552.  
  1553.  
  1554.  
  1555.  
  1556.  
  1557.  
  1558.  
  1559.  
  1560.  
  1561.  
  1562.  
  1563.  
  1564.  
  1565.  
  1566.  
  1567.  
  1568.  
  1569.  
  1570.  
  1571.  
  1572.  
  1573.  
  1574.  
  1575.  
  1576.  
  1577.  
  1578.  
  1579.  
  1580.  
  1581.  
  1582.  
  1583.  
  1584.  
  1585.  
  1586.  
  1587.                              Conserving memory space
  1588.  
  1589.  
  1590.                Success popping is controlled by the predicates "popond",
  1591.         "popoffd",  "popon",  and  "popoff".  Success popping is means of 
  1592.         reclaiming  storage which is used on backtracking to  reconstruct 
  1593.         how a particular goal was satisfied.  If it is obvious that there 
  1594.         is no alternative solution to a goal this PROLOG system is  smart 
  1595.         enough to reclaim that storage. 
  1596.  
  1597.              In  this system,  succees popping is an expensive operation. 
  1598.         Therefore,  there  is a tradeoff of memory versus  time.  On  the 
  1599.         other hand, discrete use of success popping can actually speed up 
  1600.         a program by recreating structures in a more accessible form.
  1601.  
  1602.              The  definitions of the control predicates is given in  this 
  1603.         manual  and  their use is totally  optional.  The  modulation  of 
  1604.         success popping has no effect on program logic (read solution.)
  1605.              
  1606.              The  "cut"  can  save  substantial  time  and  computational 
  1607.         overhead  as well as storage.  Although the execution of the  cut 
  1608.         costs  time,  you can design your program to use cuts in critical 
  1609.         places  to  avoid unnecessary backtracking.  Thus  the  execution 
  1610.         speed of the program can actually increase. 
  1611.              
  1612.              Anyone  who  has  read Clocksin and  Mellish  is  aware,  of 
  1613.         course, that the "cut" has a powerful logical impact which is not 
  1614.         always desirable.
  1615.  
  1616.  
  1617.         popoff 
  1618.  
  1619.         See the below definition.
  1620.  
  1621.  
  1622.  
  1623.         popon
  1624.  
  1625.         The  inference  engine  does complete success popping  for  goals 
  1626.         which appear after "popon".  Consider this example: 
  1627.  
  1628.           goal :-  a, popon, b, c, popoff, d.
  1629.  
  1630.         If  no alternative solutions exist for b,  then  success  popping 
  1631.         will  reclaim storage by removing unnecessary records  describing 
  1632.         how  "b"  was  satisfied.  If the Prolog system cannot  rule  out 
  1633.         possible additional solutions,  success popping will never occur, 
  1634.         regardless of your use of "popon". 
  1635.              Since goal "d" occurs after "popoff",  success popping  will 
  1636.         never occur.
  1637.  
  1638.  
  1639.  
  1640.  
  1641.  
  1642.  
  1643.  
  1644.  
  1645.  
  1646.  
  1647.  
  1648.  
  1649.  
  1650.  
  1651.  
  1652.         popoffd
  1653.  
  1654.         If  no  "popon" or "popoff" declarations occur in a  clause,  the 
  1655.         default  action  is  determined by  "popoffd"  and  "popond".  If 
  1656.         "popoffd" has been invoked,  the default is that success  popping 
  1657.         will not occur.
  1658.  
  1659.  
  1660.  
  1661.         popond
  1662.  
  1663.         The inverse of "popoffd". Turns on default success popping.
  1664.         printf( <stream>, <term1>,<term2>,... )
  1665.  
  1666.  
  1667.  
  1668.  
  1669.  
  1670.  
  1671.  
  1672.  
  1673.  
  1674.  
  1675.  
  1676.  
  1677.  
  1678.  
  1679.  
  1680.  
  1681.  
  1682.  
  1683.  
  1684.  
  1685.  
  1686.  
  1687.  
  1688.  
  1689.  
  1690.  
  1691.  
  1692.  
  1693.  
  1694.  
  1695.  
  1696.  
  1697.  
  1698.  
  1699.  
  1700.  
  1701.  
  1702.  
  1703.  
  1704.  
  1705.  
  1706.  
  1707.  
  1708.  
  1709.  
  1710.  
  1711.  
  1712.  
  1713.  
  1714.  
  1715.  
  1716.  
  1717.  
  1718.                                  Prolog Tutorial          
  1719.  
  1720.  
  1721.                                   Introduction
  1722.  
  1723.  
  1724.  
  1725.  
  1726.              Probably  you  have heard of the language PROLOG within  the 
  1727.         last year or so. You probably wondered the following things:
  1728.  
  1729.         1) What does the name stand for? Names of computer languages are 
  1730.         almost always acronyms.
  1731.  
  1732.         2) What is it good for?
  1733.  
  1734.         3) Why now?
  1735.  
  1736.         4) Can I get a copy to play with?
  1737.  
  1738.              Congratulations! You obviously know the answer to the fourth 
  1739.         question. We now respond to the other three.
  1740.              
  1741.         1)  The  name  stands for "programming in logic." This  we  shall 
  1742.         elaborate on in depth later on.
  1743.  
  1744.         2) PROLOG is good for writing question answering systems.  It  is 
  1745.         also   good   for  writing  programs  that  perform   complicated 
  1746.         strategies  that  compute the best or worst way to  accomplish  a 
  1747.         task, or avoid an undesirable result.
  1748.  
  1749.         3) PROLOG was virtually unknown in this country until researchers 
  1750.         in  Japan announced that it was to be the core language  of  that 
  1751.         country's fifth generation computer project.  This is the project 
  1752.         with  which  Japan hopes to achieve a domainant position  in  the 
  1753.         world information industry of the 1990's. 
  1754.  
  1755.              PROLOG  is  one of the most unusual computer languages  ever 
  1756.         invented.  It  cannot be compared to  FORTRAN,  PASCAL,  "C",  or 
  1757.         BASIC.  The facilities complement,  rather than replace those  of 
  1758.         conventional  languages.  Although  it  has great  potential  for 
  1759.         database  work,  it  has  nothing in  common  with  the  database 
  1760.         languages used on microcomputers.
  1761.  
  1762.              Perhaps  the  best point to make is that while  conventional 
  1763.         languages are prescriptive, PROLOG is descriptive. A statement in 
  1764.         a conventional language might read:
  1765.  
  1766.              if( car_wheels = TRUE ) then
  1767.                begin
  1768.                  (some sort of procedure)
  1769.                  X = X + 1;
  1770.                end 
  1771.  
  1772.  
  1773.  
  1774.  
  1775.  
  1776.  
  1777.  
  1778.  
  1779.  
  1780.  
  1781.  
  1782.  
  1783.  
  1784.         A statment in PROLOG could just be a statment of fact about  cars 
  1785.         and wheels. There are many relationships that hold. For instance,
  1786.  
  1787.              has( car, wheels ).
  1788.  
  1789.              has( car, quant(wheels, four) ).
  1790.  
  1791.              round( wheels ).
  1792.  
  1793.         Each  of  these statments is an independent fact  relating  cars, 
  1794.         wheels,  and  the  characteristics of wheels.  Because  they  are 
  1795.         independent, they can be put into a PROLOG program by programmers 
  1796.         working separately. The man who is a specialist on car bodies can 
  1797.         say  his thing,  the wheel specialist can have his say,  and  the 
  1798.         participants can work with relative independence. And this brings 
  1799.         to light a major advantage of PROLOG:
  1800.  
  1801.  
  1802.                              PARALLEL PROGRAMMING!!!
  1803.                             
  1804.  
  1805.         With  conventional  programming languages projects can  still  be 
  1806.         "chunked",  or  divided between programmers.  But efficiency on a 
  1807.         team  project  drops  drastically below that  of  the  individual 
  1808.         programmer  wrapped  up  in  his own trance.  As  the  number  of 
  1809.         participants    grows   the   need   for   communication    grows 
  1810.         geometrically. The time spent communicating can exceed that spent 
  1811.         programming! 
  1812.              Although   PROLOG   does   not  eliminate   the   need   for 
  1813.         task  coordination,  the problem is considerably  simplified.  It 
  1814.         also provides the ability to answer questions in a "ready to  eat 
  1815.         form."  Consider your favorite BASIC interpreter.  Based upon the 
  1816.         statements about cars and wheels previously given,  could you ask 
  1817.         it the following question?   
  1818.  
  1819.                        
  1820.               has( car, X ), round( X ).
  1821.  
  1822.              Does  a  car  have anything which  is  round?  The  question 
  1823.         instructs the PROLOG interpreter to consider all the objects that 
  1824.         it  knows are possessed by a car and find those which are  round. 
  1825.         Perhaps  you are beginning to guess that PROLOG has the abilities 
  1826.         of a smart database searcher.  It can not only find the facts but 
  1827.         selectively find them and interpret them.
  1828.  
  1829.  
  1830.  
  1831.  
  1832.  
  1833.  
  1834.  
  1835.  
  1836.  
  1837.  
  1838.  
  1839.  
  1840.  
  1841.  
  1842.  
  1843.  
  1844.  
  1845.  
  1846.  
  1847.  
  1848.  
  1849.  
  1850.              Consider the problem of a fault tree, as exemplified by this 
  1851.         abbreviated one:
  1852.  
  1853.  
  1854.  
  1855.         {Car won't start}
  1856.              | 
  1857.              | 
  1858.         [Engine  turns  over](No) --> [Battery voltage](no)-\
  1859.                 (Yes)                                       v
  1860.                  |                                  {Check battery}
  1861.                  |
  1862.         [Smell gasoline](yes) --> {Try full throttle cranking}
  1863.                  |                       (failure)
  1864.         /--------/                           |
  1865.  
  1866.                             (details omitted)
  1867.  
  1868.  
  1869.  
  1870.              The fault tree is easily programmed in BASIC. Later we shall 
  1871.         show  that  PROLOG supplies a superior replacement for the  fault 
  1872.         tree.  Though the tree is capable of diagnosing only the  problem 
  1873.         for  which  it was designed,  PROLOG dynamically  constructs  the 
  1874.         appropriate  tree from facts and rules you have provided.  PROLOG 
  1875.         is not limited to answering one specific question.  Given  enough 
  1876.         information,  it  will attempt to find all deductive solutions to 
  1877.         any problem.
  1878.  
  1879.  
  1880.  
  1881.  
  1882.  
  1883.  
  1884.  
  1885.  
  1886.  
  1887.  
  1888.  
  1889.  
  1890.  
  1891.  
  1892.  
  1893.  
  1894.  
  1895.  
  1896.  
  1897.  
  1898.  
  1899.  
  1900.  
  1901.  
  1902.  
  1903.  
  1904.  
  1905.  
  1906.  
  1907.  
  1908.  
  1909.  
  1910.  
  1911.  
  1912.  
  1913.  
  1914.  
  1915.  
  1916.  
  1917.                                   PROLOG PRIMER
  1918.  
  1919.         I.                       Rules and Facts     
  1920.  
  1921.  
  1922.  
  1923.              This  is  where you should start if you know  nothing  about 
  1924.         PROLOG. Let us consider a simple statment in PROLOG, such as:
  1925.  
  1926.         1)   has( car, wheels ).
  1927.  
  1928.         This  statement  is a "fact.  The word "has" in this statment  is 
  1929.         known  either  as a functor or predicate.  It is a name  for  the 
  1930.         relationship  within the parenthesis.  It implies that a car  has 
  1931.         wheels.  But  the  order  of  the words  inside  the  bracket  is 
  1932.         arbitrary and established by you. You could just as easily say:
  1933.  
  1934.         2)   has( wheels, car ).
  1935.  
  1936.         and if you wrote this way consistently,  all would be  well.  The 
  1937.         words  has,  wheels,  and car are all PROLOG atoms.  "Wheels" and 
  1938.         "car" are constants. 
  1939.              
  1940.         A   database   of  facts  can  illustrate  the   data   retrieval 
  1941.         capabilities of PROLOG. For instance:
  1942.  
  1943.         3)   has( car, wheels ).
  1944.              has( car, frame ).
  1945.              has( car, windshield ).
  1946.              has( car, engine ).
  1947.  
  1948.         You could then ask PROLOG the question:
  1949.  
  1950.         4)   has( car, Part ).
  1951.  
  1952.         The  capital  "P" of Part means that Part is a  variable.  PROLOG 
  1953.         will make Part equal to whatever constant is required to make the 
  1954.         question match one of the facts in the database. Thus PROLOG will 
  1955.         respond:
  1956.  
  1957.              Part = wheels.
  1958.              
  1959.              More?(Y/N):
  1960.  
  1961.         If you type "y" the next answer will appear:
  1962.  
  1963.              Part = frame.
  1964.  
  1965.              More?(Y/N):
  1966.  
  1967.         If you continue, PROLOG will produce the answers Part = windshield 
  1968.         and Part = engine. Finally, you will see:
  1969.  
  1970.              More?(Y/N):y
  1971.  
  1972.              No.
  1973.          
  1974.         indicating that PROLOG has exhausted the database.  Incidentally, 
  1975.         when  a  variable is set equal to a constant or  other  variable, 
  1976.  
  1977.  
  1978.  
  1979.  
  1980.  
  1981.  
  1982.         it is said to be instantiated to that object.
  1983.  
  1984.              Notice  that  PROLOG searches the database forwards  and  in 
  1985.         this case,  from the beginning.  The forward search path is built 
  1986.         into PROLOG and cannot be changed. An author of a program written 
  1987.         in  a  prescriptive language is quite conscious of the  order  of 
  1988.         execution  of  his program,  while in PROLOG it is  not  directly 
  1989.         under his control.
  1990.              
  1991.              The other major element is the rule which is a fact which is 
  1992.         conditionally true. In logic this is called a Horn clause: 
  1993.  
  1994.  
  1995.         5)   has( X, wheels ) :- iscar( X ).
  1996.  
  1997.         The  fact iscar( car ) and the above rule are equivalent to
  1998.  
  1999.         6)   has( car, wheels).
  2000.  
  2001.         The  symbol :- is the "rule sign." The expression on the left  of 
  2002.         :-is the "head" and on the right is the body.  The variable X has 
  2003.         scope  of the rule,  which means that it has meaning only  within 
  2004.         the rule.  For instance,  we could have two rules in the database 
  2005.         using identically named variables.
  2006.  
  2007.  
  2008.         7)   has( X,  transportation ) :- 
  2009.                            has( X,  car ), has( license, X ).
  2010.  
  2011.         8)   has( X, elephant ) :- istrainer( X ), hasjob( X ).
  2012.  
  2013.         The  variables  X in the two expressions are completely  distinct 
  2014.         and have nothing to do with each other.
  2015.  
  2016.         The comma between has( X, car ) and has( license, X ) means "and" 
  2017.         or logical conjuction.  The rule will not be true unless both the 
  2018.         clauses has(X, car) and has( license, X ) are true.
  2019.  
  2020.  
  2021.              On the other hand if there is a rule
  2022.              
  2023.         9)   has( license, X ) :- passedexam( X ).
  2024.  
  2025.         consider what PROLOG will do in response to the question:
  2026.  
  2027.         10)  has( harry, transportation ).
  2028.  
  2029.         (Notice  that  harry has not been capitalized because we  do  not 
  2030.         want  it  taken as a variable.  We could,  however,  say  'Harry' 
  2031.         enclosed in single quotes.)
  2032.  
  2033.              It  will scan the database and use (7),  in which X will  be 
  2034.         instantiated to harry. The rule generates two new questions:
  2035.  
  2036.         11)  has( harry, car ).
  2037.  
  2038.         12)  has( license, harry ).
  2039.  
  2040.         Assuming  that  harry  has  a car,  the first clause  of  (7)  is 
  2041.         satisfied and the database is scanned for a match to (12). PROLOG 
  2042.  
  2043.  
  2044.  
  2045.  
  2046.  
  2047.  
  2048.         picks  up  rule (9) in which X is instantiated to harry  and  the 
  2049.         question is now posed:
  2050.  
  2051.         13)  passedexam( harry ).
  2052.  
  2053.              If there is a fact:
  2054.  
  2055.              passedexam( harry ).
  2056.  
  2057.         in  the database then all is well and harry  has  transportation. 
  2058.         If there is not, then PROLOG will succinctly tell you:
  2059.  
  2060.              No.
  2061.  
  2062.         But  suppose Harry has money and can hire a chauffer as any  good 
  2063.         programmer  can.  That  could be made part of the program in  the 
  2064.         following way.
  2065.  
  2066.              The rule which PROLOG tried to use was:
  2067.  
  2068.         14)  has( X,  transportation ) :- 
  2069.                            has( X,  car ), has( license, X ).
  2070.  
  2071.         At any point following it there could be included another rule:
  2072.  
  2073.         15)  has( X, transportation ) :- has( X, money ).
  2074.  
  2075.         or simply the bald fact:
  2076.  
  2077.         16)  has( harry, transportation ).
  2078.  
  2079.              These  additional  rules  or  facts would  be  used  in  two 
  2080.         circumstances.  If at any point a rule does not yield a solution, 
  2081.         PROLOG   will  scan  forward  from  that  rule  to  find  another 
  2082.         applicable  one.  This process is known as "backtracking  search" 
  2083.         and can be quite time consuming.
  2084.  
  2085.  
  2086.         If  in response to the "More?" prompt you answer "y" PROLOG  will 
  2087.         search  for an additional distinct solution.  It will attempt  to 
  2088.         find an alternate rule or fact for the last rule or fact used. If 
  2089.         that  fails,  it  will back up to the antecedent rule and try  to 
  2090.         find  an alternate antecedent.  And it will continue to  back  up 
  2091.         until  it  arrives at the question you asked,  at which point  it 
  2092.         will say:
  2093.  
  2094.              No.
  2095.  
  2096.         "Antecedent"  to a rule means that it gave rise to its' use.  For 
  2097.         example,  (7)  is  the antecedent of (9) in the  context  of  the 
  2098.         question (16).
  2099.  
  2100.  
  2101.  
  2102.  
  2103.         II.                          Grammar
  2104.  
  2105.              It is a boring subject, but it must be discussed. All PROLOG 
  2106.         statements are composed of valid terms, possibly a rule sign (":-
  2107.         "),  commas representing conjunction ("and"), and a period at the 
  2108.  
  2109.  
  2110.  
  2111.  
  2112.  
  2113.  
  2114.         very end.
  2115.              A term is a structure, constant, variable, or number.
  2116.          
  2117.              What is a structure? It is a kind of grouping:
  2118.  
  2119.              1) Structures consist of a functor, and a set of objects or
  2120.                 structures in parenthesis.
  2121.  
  2122.              2)  Objects are constants,  variables,  numbers,  or  lists, 
  2123.                 which we have not discussed yet.
  2124.  
  2125.              3)  A  constant or functor must be a string of  letters  and 
  2126.                 numbers, beginning with a lower case letter, unless
  2127.                 you  choose  to  enclose  it in single  quotes  (  'howdy 
  2128.                 pardner'  ),  in  which  case you are  freed  from  these 
  2129.                 restrictions.
  2130.              4) A  variable  must be a string of  letters  and  numbers 
  2131.                 beginning with a capital letter.
  2132.              
  2133.              5) A  functor  may optionally have  arguments  enclosed  in 
  2134.                 parenthesis , as in: hascar( X ) or hascar. 
  2135.  
  2136.         An example:  "has( X, transportation )." is a structure.
  2137.  
  2138.  
  2139.  
  2140.  
  2141.  
  2142.  
  2143.  
  2144.  
  2145.  
  2146.  
  2147.  
  2148.  
  2149.  
  2150.  
  2151.  
  2152.  
  2153.  
  2154.  
  2155.  
  2156.  
  2157.  
  2158.  
  2159.  
  2160.  
  2161.  
  2162.  
  2163.  
  2164.  
  2165.  
  2166.  
  2167.  
  2168.  
  2169.  
  2170.  
  2171.  
  2172.  
  2173.  
  2174.  
  2175.  
  2176.  
  2177.  
  2178.  
  2179.  
  2180.         III.                     Input / Output      
  2181.  
  2182.              You   now   know  enough  to  write  simple  databases   and 
  2183.         interrogate   them  profitably.   But  before  we  examine   more 
  2184.         sophisticated  examples,  it  will be necessary to add input  and 
  2185.         output to the language. There are built in functions which appear 
  2186.         as rules which are satisfied once. Thus the statment:
  2187.  
  2188.              write( 'Hello world.' ).
  2189.  
  2190.         can be included on the right side of a rule:
  2191.  
  2192.  
  2193.         greetings(  X ) :- ishuman( X ),  write( 'Hello world.' ).  You 
  2194.         can  also write "write( X )" where X is some variable.  Note that 
  2195.         'Hello  world.' is not enclosed in double quotes.  Single quotes, 
  2196.         which denote a constant, are required. Double quotes would denote 
  2197.         a list, which is another thing entirely.
  2198.  
  2199.         Provided  that  a match to "ishuman" can be  found,  the  builtin 
  2200.         function  "write"  is  executed and the message  printed  to  the 
  2201.         screen.
  2202.              The  builtin  read( X ) reads a "structure" that  you  input 
  2203.         from the keyboard. More formally, we have
  2204.  
  2205.              read( <variable> or <constant> )
  2206.              write( <variable> or <constant> )
  2207.  
  2208.         If you write read( Input ),  then the variable "keyboard" will be 
  2209.         assigned to whatever is typed at the keyboard,  provided that the 
  2210.         input  is a valid PROLOG structure.  The builtin "read" will fail 
  2211.         if instead of Keyboard we wrote read( baloney ),  where "baloney" 
  2212.         is a constant,  and the user at the keyboard did not type exactly 
  2213.         "baloney." 
  2214.  
  2215.         When you input a structure in response to a "read" statement,  be 
  2216.         sure to end it with a period and an <ENTER>. 
  2217.  
  2218.              There  is  a convenient way of putting the cursor on  a  new 
  2219.         line. This is the builtin "nl". For example:
  2220.  
  2221.              showme :- write( 'line 1' ), nl, write( 'line 2' ). 
  2222.  
  2223.         would result in:
  2224.  
  2225.              line 1
  2226.              line 2
  2227.  
  2228.              There  is  also a primitive form of input/output for  single 
  2229.         characters. It will be discussed later.
  2230.  
  2231.  
  2232.  
  2233.  
  2234.  
  2235.  
  2236.  
  2237.  
  2238.  
  2239.  
  2240.  
  2241.  
  2242.  
  2243.  
  2244.  
  2245.  
  2246.         IV.                   A Fault Tree Example
  2247.  
  2248.              Consider the "won't start" fault tree for an automobile:
  2249.  
  2250.         {Car won't start}
  2251.              | 
  2252.              | 
  2253.         [Engine  turns  over](No) --> [Battery voltage](no)-\
  2254.                 (Yes)                                       v
  2255.                  |                                  {Check battery}
  2256.                  |
  2257.         [Smell gasoline](yes) --> {Try full throttle cranking}
  2258.                  |                       (failure)
  2259.         /--------/                           |
  2260.         |           /------------------------/ 
  2261.         |           |                       
  2262.         |           |
  2263.         |  [Check for fuel line leaks](yes)-->{Replace fuel line}
  2264.         |          (no)
  2265.         |           |
  2266.         |           |
  2267.         |  [Check for defective carburator](yes)--\
  2268.         |          (no)                           v
  2269.         |                                {Repair carburator}
  2270.         \----\
  2271.              |
  2272.              |
  2273.         [Is spark present](no)-->[Do points open and close](no)-\
  2274.              |                             (yes)                v
  2275.         /----/                               |          {Adjust points}
  2276.         |           /------------------------/
  2277.         |           |
  2278.         |  [Pull distributor wire, observe spark](blue)--\
  2279.         |        (orange)                                v
  2280.         |           |                           {Check plug wires & cap}
  2281.         |           |
  2282.         |  [Measure voltage on coil primary](not 12V)--\
  2283.         |         (12V)                                v
  2284.         |           |              {Check wiring, ballast resistor}
  2285.         |           |
  2286.         |  [Check condenser with ohmmeter](conducts)--\
  2287.         |    (no conduction)                          v
  2288.         |           |                         {Replace condenser}
  2289.         |           |
  2290.         |  [Open and close points](voltage not 0 - 12)--\
  2291.         |   (voltage swings 0 - 12)                     v
  2292.         |           |                         {Fix primary circuit}
  2293.         |           |
  2294.         |  {Consider hidden fault, swap components]
  2295.         |
  2296.         |
  2297.         \-------{Call a tow truck!!}
  2298.  
  2299.  
  2300.  
  2301.  
  2302.  
  2303.  
  2304.  
  2305.  
  2306.  
  2307.  
  2308.  
  2309.  
  2310.  
  2311.  
  2312.              A PROLOG program to  implement this is simple. Each statment 
  2313.         represents  a  decision point fragment of the  tree.  The  PROLOG 
  2314.         interpreter  dynamically  assembles  the tree as  it  attempts  a 
  2315.         solution. 
  2316.  
  2317.         'car wont start' :- write( 'Is the battery voltage low?' ), 
  2318.                             affirm, nl,
  2319.                             write( 'Check battery' ).
  2320.  
  2321.         'car wont start' :- write( 'Smell gasoline?' ), 
  2322.                             affirm, nl,
  2323.                             'fuel system'.
  2324.  
  2325.         'fuel system'    :- write( 'Try full throttle cranking' ).
  2326.  
  2327.         'fuel system'    :- write( 'Are there fuel line leaks?' ),
  2328.                             affirm, nl,
  2329.                             write( 'Replace fuel line.' ).
  2330.  
  2331.         'fuel system'    :- write( 'Check carburator' ).
  2332.  
  2333.         'car wont start' :- write( 'Is spark present?' ),
  2334.                             not( affirm ), nl,
  2335.                             'no spark'.
  2336.  
  2337.         'no spark'       :- write( 'Do points open and close?' ),
  2338.                             not( affirm ), nl,
  2339.                             write( 'Adjust or replace points.' ).
  2340.  
  2341.         'no spark'       :- write( 'Is the spark off the coil good?' ),
  2342.                             affirm,
  2343.                             write( 'Check plug wires and cap.' ).
  2344.  
  2345.         'no spark'       :- write( 'What is the voltage on the primary
  2346.                              of the coil: ' ), 
  2347.                             read( Volts ), 
  2348.                             Volts < 10,
  2349.                             nl,
  2350.                             write('Check wiring and ballast resistor.').
  2351.  
  2352.         'no spark'       :- write( 'Does the capacitor leak?' ),
  2353.                             affirm,
  2354.                             write( 'Replace the capacitor.' ).
  2355.  
  2356.         'no spark'       :- not( 'primary circuit' ).
  2357.  
  2358.         'primary circuit' 
  2359.                          :- write( 'Open the  points.  Voltage  across 
  2360.                               coil?:'), nl,
  2361.                             read( Openvolts ), Openvolts < 1, 
  2362.                             write(  'Close the points.  Voltage  across 
  2363.                               coil?:'),
  2364.                             read( Closevolts ), Closevolts > 10, nl,
  2365.                             write( 'Primary circuit is OK.' ). 
  2366.  
  2367.         'no spark'       :- write( 'Consider a hidden fault. Swap
  2368.                               cap, rotor,points,capacitor.' ).
  2369.  
  2370.  
  2371.         'Car wont start' :- write( 'Get a tow truck!!' ).
  2372.  
  2373.  
  2374.  
  2375.  
  2376.  
  2377.  
  2378.  
  2379.  
  2380.                                  --End program--
  2381.  
  2382.  
  2383.              The  above  is  a  simple example of  an  expert  system.  A 
  2384.         sophisticated  system would tell you exactly the method by  which 
  2385.         it  has reached a conclusion.  It would communicate by a  "shell" 
  2386.         program  written  in PROLOG which would accept a wider  range  of 
  2387.         input   than  the  "valid  structure"  required  by  the   PROLOG 
  2388.         interpreter directly.
  2389.  
  2390.  
  2391.  
  2392.  
  2393.  
  2394.  
  2395.  
  2396.  
  2397.  
  2398.  
  2399.  
  2400.  
  2401.  
  2402.  
  2403.  
  2404.  
  2405.  
  2406.  
  2407.  
  2408.  
  2409.  
  2410.  
  2411.  
  2412.  
  2413.  
  2414.  
  2415.  
  2416.  
  2417.  
  2418.  
  2419.  
  2420.  
  2421.  
  2422.  
  2423.  
  2424.  
  2425.  
  2426.  
  2427.  
  2428.  
  2429.  
  2430.  
  2431.  
  2432.  
  2433.  
  2434.  
  2435.  
  2436.  
  2437.  
  2438.  
  2439.  
  2440.  
  2441.  
  2442.  
  2443.  
  2444.         V.                            Lists               
  2445.  
  2446.              Consider  a  shopping list given you by your wife.  It is  a 
  2447.         piece of paper with items written on it in an order that probably 
  2448.         symbolizes  their  importance.  At the top it  may  say  EGGS!!!, 
  2449.         followed by carrots, hamburger, and finally a flea collar for the 
  2450.         dog, if you can find one. In PROLOG such a list would be written:
  2451.  
  2452.         1)   [eggs, carrots, hamburger, fleacollar]
  2453.  
  2454.         The  order of a list is important so that eggs and carrots cannot 
  2455.         be reversed and PROLOG be uncaring.
  2456.  
  2457.         Let us put the list in a structure:
  2458.  
  2459.              shopping( [eggs, carrots, hamburger, fleacollar] ).
  2460.  
  2461.         Then  if you wished to isolate the head of the list you could ask 
  2462.         the question:
  2463.  
  2464.              shopping( [ Mostimportant | Rest ] ).
  2465.  
  2466.         and PROLOG would respond:
  2467.  
  2468.              Mostimportant   =  eggs,   
  2469.              Rest   =   [carrots,   hamburger, fleacollar].
  2470.  
  2471.         The vertical bar "|" is crucial here. It is the string extraction 
  2472.         operator,  which  performs  a  combination  of the  CDR  and  CAR 
  2473.         functions  of LISP.  When it appears in the context [X|Y] it  can 
  2474.         separate the head of the list from the rest, or tail.
  2475.  
  2476.  
  2477.              You  may have gained the impression that PROLOG is a  rather 
  2478.         static language capable of answering simple questions,  but it is 
  2479.         far  more powerful than that.  The string extraction operator  is 
  2480.         the  key.  It permits PROLOG to whittle a complex expression down 
  2481.         to the bare remainder.  If the rules you have given it permit  it 
  2482.         to  whittle  the  remainder  down to  nothing,  then  success  is 
  2483.         achieved. An example of this is the definition of "append."
  2484.  
  2485.              Let  us suppose you have not yet done yesterday's  shopping, 
  2486.         let alone today's. You pull it out of your wallet and sootch tape 
  2487.         it to the list your wife just gave you. Yesterday's list was:
  2488.  
  2489.              [tomatoes, onions, ketchup]
  2490.  
  2491.         Combined with [eggs, carrots, hamburger, fleacollar] we obtain
  2492.  
  2493.              [eggs,carrots,hamburger,fleacollar,tomatoes,onions,garlic].
  2494.  
  2495.         To  take one list and to attach it to the tail of another list is 
  2496.         to  "append"  the first to the second.  The PROLOG definition  of 
  2497.         append is:
  2498.  
  2499.  
  2500.  
  2501.         Rule1:     append( [], L, L ).
  2502.  
  2503.         Rule2:     append( [X|List1], List2, [X|List3] ) :-
  2504.  
  2505.  
  2506.  
  2507.  
  2508.  
  2509.  
  2510.                       append( List1, List2, List3 ].
  2511.  
  2512.         The  general  scheme is this:  
  2513.  
  2514.         The definition consists of one rule and one fact.  The rule  will 
  2515.         be used over and over again until what little is left matches the 
  2516.         fact.  The [] stands for empty list,  which is like a bag without 
  2517.         anything in it. This is an example of a recursive definition.
  2518.              Suppose we ask:
  2519.  
  2520.              append( [a,b,c], [d,e,f], Whatgives ).
  2521.  
  2522.         1. Rule 2 is invoked with arguments ( [a,b,c], [d,e,f], Whatgives ).
  2523.         2. Rule 2 is invoked again with arguments:
  2524.              ( [b,c], [d,e,f], List3 ).
  2525.         3. Rule 2 is invoked again with arguments:
  2526.              ( [b], [d,e,f], List3 ).
  2527.         4.  The  arguments  are now ([],  [d,e,f],  List3 ).  Rule 1  now 
  2528.             matches. End.
  2529.  
  2530.         How does this cause a list to be constructed? The key is to watch 
  2531.         the   third  argument.   Supplied  by  the  user,   it  is  named 
  2532.         "Whatgives". The inference engine matches it to [X|List3] in rule 
  2533.         2. Now lets trace this as rule two is successivly invoked: 
  2534.  
  2535.  
  2536.                 Whatgives                                                
  2537.                    |                                                     
  2538.                    |                                                     
  2539.                    |                                                     
  2540.                    v                                                     
  2541.         Rule2:  [X|List3] (List1 = [b,c])                                
  2542.                  |  \                                                    
  2543.                  |   \                                                   
  2544.                  |    \                                                  
  2545.                  v     \                                                 
  2546.         Rule2:   a   [X'|List3'] (List1' = [c])                          
  2547.                       |    \                                             
  2548.                       |     \                                            
  2549.                       |      \                                           
  2550.                       v       \                                          
  2551.         Rule2:        b     [X''|List3''] (List1'' = [], ie., empty set.)
  2552.                               |    \                                     
  2553.                               |     \                                    
  2554.                               |      \                                   
  2555.         Rule1:                c       L  ( in Rule1 = [d,e,f] )              
  2556.                                                                          
  2557.         End.
  2558.  
  2559.  
  2560.         L in rule 1 is [d,e,f] for the following reason: Notice that rule 
  2561.         2 never alters List2. It supplies it to whatever rule it invokes. 
  2562.         So L in rule 1 is the original List2, or [a,b,c].
  2563.  
  2564.              This example would not have worked if the order of rules one 
  2565.         and  two  were  reversed.  The  PROLOG  inference  engine  always 
  2566.         attempts to use the the first rule encountered. You could imagine 
  2567.         it as always reading your program from the top down in attempting 
  2568.         to  find an appropriate rule.  Since rule 2 would always satisfy, 
  2569.         an  unpleasant  thing  would  have happened  if  the  order  were 
  2570.  
  2571.  
  2572.  
  2573.  
  2574.  
  2575.  
  2576.         reversed. The program would loop forever.
  2577.              
  2578.  
  2579.  
  2580.  
  2581.              I  hope  that  this tiny introduction to PROLOG  whets  your 
  2582.         appetite. You should now purchase the book
  2583.  
  2584.              Programming In Prolog
  2585.              W.F. Clocksin and C.S. Mellish
  2586.              Springer - Verlag
  2587.              Berlin,Heidelberg,New York. 1981,1984
  2588.  
  2589.  
  2590.  
  2591.  
  2592.  
  2593.  
  2594.  
  2595.  
  2596.  
  2597.  
  2598.  
  2599.  
  2600.  
  2601.  
  2602.  
  2603.  
  2604.  
  2605.  
  2606.  
  2607.  
  2608.  
  2609.  
  2610.  
  2611.  
  2612.  
  2613.  
  2614.  
  2615.  
  2616.  
  2617.  
  2618.  
  2619.  
  2620.  
  2621.  
  2622.  
  2623.  
  2624.  
  2625.  
  2626.  
  2627.  
  2628.  
  2629.  
  2630.  
  2631.  
  2632.  
  2633.  
  2634.  
  2635.  
  2636.  
  2637.  
  2638.  
  2639.  
  2640.  
  2641.