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
[code language=”text”]
/opt/local/bin/swipl
[/code]
To launch the prolog, type swipl in the Terminal.
[code language=”text”]
swipl
[/code]
To quit, press Ctrl-z

Prolog helloworld program, hello.pl
[code language=”text”]
/*Prolog Hello World Program*/
hello :- write(‘Hello World, This is my first program in Prolog!!!’).
[/code]

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
[code language=”text”]
swipl
[/code]

2. In prolog console, type the following to load the hello program
[code language=”text”]
[‘hello.pl’].
/*or*/
consult(hello).
[/code]
And then type the following to run it
[code language=”text”]
hello.
[/code]

3. To print the string directly in the prolog console, type the following
[code language=”text”]
write(‘Hello World, This is my first program in Prolog!!!’).
[/code]

4. To quit prolog console, press Ctrl-z

Search within Codexpedia

Custom Search

Search the entire web

Custom Search