Declarative programming
1 / 34

Declarative Programming - PowerPoint PPT Presentation

  • Uploaded on

Declarative Programming. How to use PROLOG environment. Autumn 2012. Getting a PROLOG interpreter - SWI-Prolog. Freely available from Getting a PROLOG interpreter - SWI-Prolog. Freely available from under GNU license

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
Download Presentation

PowerPoint Slideshow about ' Declarative Programming' - janus

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Declarative programming

Declarative Programming

How to use PROLOG


Autumn 2012

Getting a prolog interpreter swi prolog
Getting a PROLOG interpreter - SWI-Prolog

Freely available from

Getting a prolog interpreter swi prolog1
Getting a PROLOG interpreter - SWI-Prolog

  • Freely available from under GNU license

  • 5.* versions already does not seem to have apparent problems

  • This will be the "official version" used for this course

  • Comes as an installation, although just copying the directories seems to be ok

  • Includes graphical components - if you

    wish, you may use them

  • Includes a number of nice predicates

    not required by Prolog standard, but the

    use of them in home assignments

    may be limited

Getting a prolog interpreter swi prolog2
Getting a PROLOG interpreter - SWI-Prolog

  • A SWI-Prolog-Editor for Windows is also available

  • Not necessary, but might be useful

Getting a prolog interpreter sicstus prolog
Getting a PROLOG interpreter - Sicstus Prolog

Available from

Getting a prolog interpreter sicstus prolog1
Getting a PROLOG interpreter - Sicstus Prolog

  • Available from

  • Unfortunately not free any more (even educational licenses)

  • You can get a 30-day evaluation version

  • Might be better that SWI-Prolog (this was true some time

    ago, but SWI-Prolog has improved a lot)

  • Installation is required

  • With few exceptions programs

    are compatible with SWI-Prolog

    (if you don't use non-stadard


Getting a prolog interpreter other
Getting a PROLOG interpreter - other

Other interpreters are available. You may use them, but compatibility with SWI-Prolog is your problem.

The beginning
The beginning

When starting the interpreter you will see something like this:

You can load an existing prolog program (assuming its name

is '') by typing:

[your_program]. or ['']. or

consult(your_program). or consult('your_program').

and pressing <Enter>

Loading a prolog program
Loading a prolog program

  • The dot ('.') at the end of input command is mandatory

  • You must use apostrophes around file name, if it contains

    special symbols (e.g. '.')

  • '.pl' is considered a native extension for prolog files and may

    be omitted (some interpreters use other native extensions,

    e.g. '.pro')

  • you can load several programs simultaneously, e.g.


  • pay attention to warning and

    error messages

  • consult in SWI-Prolog seems

    to correspond to the standard

    predicate reconsult, which

    here is missing

Writing a prolog program
Writing a prolog program

  • You can write a new prolog program by using command

    [user]. or consult(user).

  • This means you should not use names 'user' and ''

    for your program files :)

  • Saving and reusing of a program composed in this way

    might be difficult or impossible (depending from interpreter

    you are using)

  • To terminate the writing and to return to prolog prompt use

    <Ctrl>+D (although just typing

    of single '.' works in some


Executing queries
Executing queries

  • When the program is loaded you may give queries to

    prolog interpreter, e.g. rule1(a).

  • Queries also must terminate with dot ('.')

  • Depending from the query you will receiver either answer

    yes or no (or get a 'stack owerflow' message or never any

    result at all :)

Executing queries1
Executing queries

  • Basically yes/no are the sole results a logic programming

    language is expected to produce (but later you will find out that

    Prolog actually has some basic input/output facilities)

  • Still, if your query includes a variable (e.g. rule1(X).), in the

    'yes' case prolog will produce a value for this variable that

    makes the query true

  • Now, if you continue

    with '.' the query will


  • If you continue with ';'

    the prolog will look for

    other possibilities to

    satisfy the same


Terminating the session
Terminating the session

  • Somehow this is tricky. The correct way to do this is to

    use command halt. (somehow not the most intuitive

    name for this...)

  • And <Ctrl>+Z will do as nicely...