1 / 34

Declarative Programming

Declarative Programming. How to use PROLOG environment. Autumn 2012. Getting a PROLOG interpreter - SWI-Prolog. Freely available from http://www.swi-prolog.org/. Getting a PROLOG interpreter - SWI-Prolog. Freely available from http://www.swi-prolog.org/ under GNU license

janus
Télécharger la présentation

Declarative Programming

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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Declarative Programming How to use PROLOG environment Autumn 2012

  2. Getting a PROLOG interpreter - SWI-Prolog Freely available from http://www.swi-prolog.org/

  3. Getting a PROLOG interpreter - SWI-Prolog • Freely available from http://www.swi-prolog.org/ 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

  4. Getting a PROLOG interpreter - SWI-Prolog • A SWI-Prolog-Editor for Windows is also available • Not necessary, but might be useful

  5. Getting a PROLOG interpreter - Sicstus Prolog Available from http://www.swi-prolog.org/

  6. Getting a PROLOG interpreter - Sicstus Prolog • Available from http://www.swi-prolog.org/ • 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 predicates)

  7. Getting a PROLOG interpreter - other Other interpreters are available. You may use them, but compatibility with SWI-Prolog is your problem. http://www.binnetcorp.com/BinProlog/ http://www.amzi.com/download/

  8. The beginning When starting the interpreter you will see something like this: You can load an existing prolog program (assuming its name is 'your_program.pl') by typing: [your_program]. or ['your_program.pl']. or consult(your_program). or consult('your_program'). and pressing <Enter>

  9. 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. [your_program_1,your_program_2]. • pay attention to warning and error messages • consult in SWI-Prolog seems to correspond to the standard predicate reconsult, which here is missing

  10. 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 'user.pl' 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 versions)

  11. 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 :)

  12. 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 terminate • If you continue with ';' the prolog will look for other possibilities to satisfy the same query

  13. 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...

  14. SWI-Prolog packages

  15. SWI-Prolog packages

  16. Using SWI-Prolog

  17. Using SWI-Prolog

  18. Using SWI-Prolog

  19. Using SWI-Prolog

  20. Using SWI-Prolog

  21. Using SWI-Prolog

  22. Using SWI-Prolog

  23. Using SWI-Prolog

  24. Using SWI-Prolog

  25. Using SWI-Prolog

  26. SWI-Prolog and C++

  27. Using DevStudio

  28. Using DevStudio

  29. Using plld.exe

  30. SWI-Prolog - Installation

  31. SWI-Prolog - Installation

  32. SWI-Prolog - Installation

  33. SWI-Prolog - Installation

  34. SWI-Prolog - Installation

More Related