Examples of procedural languages are BASIC, C, Pascal and Python.
This program is very small so does not have a procedure, however is does show that the programmer created a set of instructions which are executed in order to provide a solution to a problem.
Declarative languages
Declarative languages are often used by intelligent systems. Declarative languages are very different to the other types of language because of the way that the language is structured. Programmers will create a knowledge base. A knowledge base contains a series of related facts and rules that can be queried to provide solutions. Examples of Declarative programming languages are: PROLOG, Lisp.
Example
Suppose we want to find out whether a person drives a fast car. We start by building a set of facts and rules for our knowledge base.
facts
What is means:-
judy is a person
james is a person
james drives a car that is a ford escort
judy drives a car that is a porche
X drives a fast car IF X drives a car that is a porche
rule
In this example we could ask the program to tell us whether Judy drives a fast car by typing the query:
?drives_fast_car(judy)
The result would be YES since the goal is satisfied.
If we asked:
?drives_fast_car(james)
then the result would be NO as drives_car(james, porche) would fail and the goal is not satisfied.
Contrast this with a procedural language where the programmer would need to set up a structure to hold the knowledge and predefine its type (string, number etc). Then they would need to describe the steps taken to search the structure in order to answer the query.
X and Y represent variables; when using Prolog, variables should always be written as capital letters but declarative languages do not require the programmer to declare a data type. It is necessary to be able to read, understand and create simple facts and rules in the format shown.
Queries depend upon in-built algorithms that will carry out pattern matching to return a result. Heuristic, breadth-first and depth-first searches are often used to perform pattern matching when querying a knowledge base.
Declarative languages like Prolog allow for the use of self-modifying code. This means that during execution the program can modify the facts and rules that it holds if necessary.
Share with your friends: |