Logical programming languages: features, examples

How often did you come across the obscure term “logical programming” and couldn't understand what it was? Today we will finally determine what programming languages ​​are of a logical type, and consider examples of such languages.

Before starting a language review, you must first find out what it is and why it is needed.

What is logical programming?

Tree of languages




This is an approach to programming based on the proof of theorems and the derivation of information based on facts. Conclusion of the result is a by-product of the program. Logical programming is based on the theory of mathematical logic, includes a section of discrete mathematics and some others.

What are the differences?

Many combine logical programming languages ​​with functional languages, but they have some differences, which we will discuss later.

Unlike functional ones, logic ones are very well suited for creating artificial intelligence. It is also sometimes very convenient when variables in a language are not divided into input and output. It is in such languages ​​that this happens, which sometimes simplifies working with code. Again, the programs are faster and sometimes perform their tasks more efficiently. The main feature of logical programming languages ​​is that the program represents certain relationships between elements.





However, there are also disadvantages. Not everything can be described using logic, therefore, in such programs, functions will not always work as they should, or will not work at all.

Who benefits from learning logical type programming languages?

It is worth immediately answering the question: learning these languages ​​is useful to everyone - from a schoolboy to a person of age. After all, logical programming languages ​​can literally make our brain think logically. Also, such languages ​​will be very useful in creating artificial intelligence or when working with data.

Logical programming languages

There are not many such languages, and they differ from each other. We’ll only talk about two, but start with the one that started the era of logical languages, and his name is Prolog.

Prolog language




This language was developed in 1972 by Alain Kolmeroe and is relevant and fresh today. Although this is not the simplest language in terms of syntax, it is very useful in understanding computer logic. Look at the code that describes the book:

book( '', '2009', '', authors( ' ', ' ' ) ).
      
      



Program Writing Example




Such a description is quite simple to understand and understand what’s what. That is why learning such a language will not make huge difficulties and will not require dancing with a tambourine.





Let's take a look at its pros and cons.

Pros.

1. The code is easy to understand and remember.

As mentioned above, the code in the Prolog language is not so difficult to write. It is quite simple, in the understanding of the average user.

2. Expressions and facts.

This language can be used without any calculations, relying only on expressions and facts.

3. The path is not affected.

Whatever path you choose to implement your idea, it almost never affects the outcome of the program.

Minuses.

Language problems




1. Weak investment.

Due to the fact that this language has little material support - it develops rather slowly, in small steps.

2. The inability to create comprehensive programs.

This language will be impossible to use without a link to another if you want to create more complex programs with great functionality.

3. Computing operations.

For computational operations, again, you have to use other languages.

Mercury

Derived from the Prolog language, Mercury is designed to solve two problems associated with the popular programming language.

1. Productivity.

Logical programming languages ​​are quite inferior in performance to the imperative type.

2. Debugging.

In languages ​​of this type, it takes quite a lot of time to debug the program, and also less checks are made for errors in the program, which sometimes causes trouble.

Mercury code example:

Hello World!

  :- module hello. :- interface. :- import_module io. :- pred main(io::di, io::uo) is det. :- implementation. main(!IO) :- io.write_string("Hello, World!\n", !IO).
      
      



The syntax and understanding of this language, as you can see, are very different from Prolog, which complicates learning a little, but some of its advantages that help solve Prolog problems are very useful.

Conclusion

A logical programming language is a language that processes expressions and facts, and gives a result of the work of this program as a side effect. Such languages ​​are very useful in creating artificial intelligence and working with data, but are rarely used without third-party programming languages.




All Articles