prolog installation, hello world program and run it

Prolog is a programming language developed by Alain Colmerauer in 1972. It is a logic programming language associated with artificial intelligence and computational linguistics. Unlike any other programming languages, prolog’s program logic is expressed in terms of relations, represented as facts and rules. A computation is initiated by running a query over these relations. Its source code files are often with the extension “.pl”.

Note: prolog statements or expressions or functions end with a period .

Download From http://www.swi-prolog.org/Download.html

Installation for Mac users
After you’ve downloaded the installer zip package, unpack it and run the installer, and it will install the binary to

/opt/local/bin/swipl

To launch the prolog, type swipl in the Terminal.

swipl

To quit, press Ctrl-z

Prolog helloworld program, hello.pl

/*Prolog Hello World Program*/
hello :- write('Hello World, This is my first program in Prolog!!!').

To run the prolog hello world program
1. Assume the above code is in a file called hello.pl, launch the prolog console from Terminal by

swipl

2. In prolog console, type the following to load the hello program

['hello.pl'].
/*or*/
consult(hello).

And then type the following to run it

hello.

3. To print the string directly in the prolog console, type the following

write('Hello World, This is my first program in Prolog!!!').

4. To quit prolog console, press Ctrl-z

Search within Codexpedia

Custom Search

Search the entire web

Custom Search