Allen Yip's "Prolog, Logic Programming and Programming Paradigm"

This page explains logic, functional, imperative, and object-oriented paradigms. It indicates that a programming language, while supporting a particular paradigm, typically may support other paradigms as well. With respect to the general computational paradigm, programming paradigms correspond to design and programming. This page mentions problem solving paradigms that support requirement analysis: lambda calculus, first order logic, and Turing machines. These are mathematical models developed to solve particular types of problems. Programming paradigms correspond to particular problem-solving models to support a particular type of task or to support many types of tasks. Programming paradigms can be thought of as models for transforming problem-solving models into executable programs.

Prolog, Logic Programming and Programming Paradigm

Recently I did research about Prolog language in my Artificial Intelligence class. I finally got a chance to see what logic programming really is. At the very start I just want to write something about Prolog, but it seems like I have so many things to talk about, so this post ends up with the title of Prolog, Logic Programming and Programming Paradigm.

Programming Paradigm

Class-based and Prototype-based, declarative programming and imperative programming, Object-oriented and procedure-oriented... all these programming paradigms are so disordered and complicated, but the Wikipedia has a brief definition of Programming Paradigm:

A programming paradigm is a fundamental style of computer programming.

Bazinga, Im really not into these methodology things, so I found this Principal Programming Paradigms chart made by Peter Van Roy:

Chart of Programming Paradigms

From this chart we know that its usual that a single language supports kinds of programming paradigms, which is not so cool for simplists. Obviously this chart desnt specify every paradigm, I quoted it because this kind of colorful charting looks really smart and the sentence under the title says:

More is not better (or worse) than less, just different.

I cant agree it any more, at the same time I cant help to add something behind this short sentence:

but less is beautiful.

Anyway, I googled it and picked up four main programming paradigms from the Wikipedia List:

  • Imperative Programming
  • Functional Programming
  • Object-oriented Programming
  • Logic Programming

note: about computational model,functional programming is besed on lambda calculus, logic programming is based on first order logic, and object-oriented and imperative programming are based on Turing machine.

Imperative Programming

First DO THIS and next DO THAT

Follow the ideas of Von Neumann, strict like training discipline, representative languages are Fortran, Pascal and C.

Functional Programming

Evaluate an expression and use the resulting value for something

Based on mathematics and theory of functions, simpler and more clean than the imperative one. lan The reason is that the paradigm originates from a purely mathematical discipline: the theory of functions, representative languages are Lisp, Erlang and Haskell. (Seems like functional programming is becoming popular...WHY)

Object-oriented Programming

Send messages between objects to simulate the temporal evolution of a set of real world phenomena

Most polular paradigm in recent decade, bases on Object concepts, supports encapsulation, inheritance and polymorhism, representative languages are Smalltalk, C++ and Java.

Logic Programming

Answer a question via search for a solution

Dramatically different from the other three main programming paradigms, based on first order logic, most applied in Artificial Intelligence, representative languages are Prolog, Mercury and Logtalk.

Logic Programming sloves problem by setting rules rather than setting steps, the results are generating by matching lots of facts and rules. Actually, the implementation of logic programming is so simple that many other languages can do, but they should spend more execution efficiency and computing cost than Logic Programming Language. As an example, next I will show you how Prolog works.


Prolog(Programming in Logic) was first conceived by a group around Alain Colmerauer in Marseille, France, in the early 1970s and the first Prolog system was developed in 1972 by Colmerauer with Philippe Roussel. Still, it widely used in many Aritificial Intelligence like Nature Language Processing, Expert System, etc. I really dont like rebuild wheels, so you guys can click here to check the Prolog tutorial "Learn Prolog Now!" wrote by Patrick Blackburn and his partners, the development tool I strongly recommend SWI-Prolog, an little fast opensource Prolog tool.

Prolog is simple but effcient, it takes just two lines to solve the hanoi problem:

// prolog hanoi move(1,X,Y,\_):-write('Move top disk from '),write(X),write(' to '), write(Y), nl. move(N,X,Y,Z):-N>1,M is N-1,move(M,X,Z,Y),move(1,X,Y,\_),move(M,Z,Y,X). view hosted with ❤ by GitHub

I will make an simple example to show the three statements that Prolog has: fact, rule and result.

Assume we have a family tree like this:

Family tree chart

Define the facts and rules in like this:

/* 事实 */

/* 规则 */

The results begin with " ?- ", query like this :

Query demonstration

Whats more, we can also use prolog to solve NLP or Expert System stuff, the basic mechanism is nearly the same.

Creative Commons License This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License.

Last modified: Thursday, November 2, 2017, 3:05 PM