HELP PROLOG Chris Mellish, July 1983 Rewritten Simon Nichols, September 1993 An introduction to the Poplog Prolog subsystem. CONTENTS - (Use g to access required sections) 1 Introduction 2 Running Prolog 3 Initialisation 4 Command Line Arguments 5 Prolog and Pop-11 6 Related documentation ----------------------------------------------------------------------- 1 Introduction ----------------------------------------------------------------------- Poplog Prolog is an Edinburgh-style Prolog system modelled on the "core" Prolog system described in "Programming in Prolog" by Clocksin and Mellish (published by Springer Verlag, 1981). This is broadly similar to DEC-10 Prolog in syntax and semantics, though not identical: there are differences both in syntax (described in HELP * SYNTAX) and semantics (described in HELP * POPLOG). Note: most of the documentation files cross-referenced here are directly available only when running the Prolog subsystem. To read the files outside of Prolog, use the " prolog" command from Ved. For example: prolog help poplog prolog help syntax To see a list of the available Prolog help files, use the Ved command: prolog help plogindex For information about using the Poplog editor Ved in conjunction with Prolog, see HELP * VED. ----------------------------------------------------------------------- 2 Running Prolog ----------------------------------------------------------------------- Prolog is supplied as a Poplog saved-image. To run it, give "prolog" as an argument to the Pop-11 command invoked from the shell or DCL, as follows: $ pop11 +prolog Most sites should have a command abbreviation installed for this which will allow you to type just: $ prolog instead. In either case, Prolog will print up a version banner, followed by the word "Setprolog" and the interactive top-level query mode prompt "?-", something like this: Sussex Poplog (Version 15.03 Thu Jun 20 16:20:20 BST 1996) Copyright (c) 1982-1996 University of Sussex. All rights reserved. Prolog (Version 3.2) Setprolog ?- "Setprolog" is printed whenever the Prolog system is reset: on start-up, or after an error or an interrupt. The prompt indicates that Prolog is waiting for new input in query mode (see HELP * COMPILE): you can then type either a goal to be evaluated or a Prolog command. If you enter a goal which Prolog can prove, it prints out the values of the variables in the instance it proved (assuming that there are variables in the goal). You can then type ";" and return to ask for alternatives, or anything else (terminated by ) to say that you are satisfied. Commands are not a part of Prolog: they are an addition to Prolog to allow access to features of the Poplog system. Useful commands to try are: - help Displays documentation on the given topic - source Edits the definition of the named predicate - ved Invokes the editor on a file - bye Exits Prolog The full set of commands is described in HELP * COMMANDS. A short Prolog session invoked from the operating system might appear as follows: $ prolog Sussex Poplog (Version 15.03 Thu Jun 20 16:20:20 BST 1996) Copyright (c) 1982-1996 University of Sussex. All rights reserved. Prolog (Version 3.2) Setprolog ?- [-listpreds]. % reconsult the file 'listpreds.pl' yes ?- append(X, Y, [a,b,c,d,e]). % a goal for Prolog to prove X = [] Y = [a, b, c, d, e] ? ; % ";" means "find alternatives" X = [a] Y = [b, c, d, e] ? % says "that's enough" yes ?- bye % "bye" means "exit from Poplog" $ For detailed information about compiling files in Prolog, both inside and outside Ved, see HELP * COMPILE. ----------------------------------------------------------------------- 3 Initialisation ----------------------------------------------------------------------- You can tailor the Prolog environment to your own taste by creating a file called "init.pl" containing code which you would like executed every time you run Prolog. This could involve precompiling useful library files, executing directives or queries (see HELP * DIRECTIVES), or in general anything that is valid when reconsulting a file (see HELP * COMPILE). Prolog will try to compile the "init.pl" file each time it starts up: the file is sought first in your POPLIB directory, and then failing that, in the current directory. This initialisation behaviour is the same as that of other parts of the Poplog system and is described more fully in HELP * INITIAL. Prolog also compiles the "init.p" files described in that file for general Poplog initialisation, and an "init.pl" file in the POPSYS directory for site-wide bug fixes or patches. ----------------------------------------------------------------------- 4 Command Line Arguments ----------------------------------------------------------------------- The Prolog image respects all the standard Poplog command-line arguments described fully in the introduction to REF * SYSTEM. Of these, the most useful to Prolog users are: %x initialises the X interface (where applicable). Currently there is no support for driving X directly from Prolog, but the X-based version of the editor (XVed) does become available. %nort suppresses run-time actions: recommended when making saved images. ved im help invoke the corresponding VED (or XVed) commands. Example: $ prolog %x ved mylib.pl Starts up Prolog and immediately invokes XVed on the file "mylib.pl". ----------------------------------------------------------------------- 5 Prolog and Pop-11 ----------------------------------------------------------------------- From inside Prolog you can get to the Pop-11 top-level either with the command: ?- pop11 or by invoking the predicate prolog_language/1 with the atom 'pop11' as argument: ?- prolog_language(pop11). See HELP * PROLOG_LANGUAGE for details. To return, you can invoke the Prolog predicate prolog_language/1 from Pop-11 using the Pop-11 syntax word "?-" which invokes a Prolog goal as a query: : ?- prolog_language(top). See HELP * POPTOPLOG for information about using ":-" and "?-" from Pop-11. You can also return to Prolog from Pop-11 using the Pop-11 syntax word "prolog": : prolog but this also does a Setprolog, resetting Prolog and aborting any computation: thus, it is not to be recommended except for top-level, interactive use. Note that if you type "prolog" to the Pop-11 prompt in a system which does not include Prolog, the Prolog system will be automatically loaded. For help in writing mixed-language programs in Pop-11 and Prolog see HELP * MIXED_LANGUAGES. ----------------------------------------------------------------------- 6 Related documentation ----------------------------------------------------------------------- HELP * HELPFILES An overview of the contents of the Poplog Prolog HELP files HELP * PLOGINDEX A List of all of the HELP files currently in the Prolog system HELP * PLOGNEWS A chronological summary of changes to the Prolog system HELP * LIBRARIES An overview of Prolog library packages HELP * VED Using the Poplog editor Ved in conjunction with Prolog HELP * DOCUMENTATION An introduction to Poplog documentation and how to access it --- C.all/help/prolog --- Copyright University of Sussex 1996. All rights reserved.