VALLURI Vamsidhar, WONG Mei Fun , YEE Meng Yi and ZHANG Jingyuan
Compare and Contrast Functional and Logic Based
Scheme Vamsidhar Valluri, Meng Yi Yee, Jingyuan Zhang, and Mei Fun Wong
Prolog Rose Shi, Linda Shipp, Jie Song, Jamie Stephens
The first functional programming language is Lisp, but some believe that it no longer represent the latest design concepts for functional languages. Functional programming language Scheme was introduced in 1975 by Guy L. Steele Jr. as the first dialect of Lisp. Initially, it was used for research and teaching, supporting only a handful of predefined syntactic forms and procedures. Now, Scheme is a general-purpose language. Some other members of the functional programming language family are Lisp, Common Lips, ML, and Haskell.
Logic programming language is designed to be used for the development of artificial intelligence machines and natural language understanding. Its implementation as roots in research on theorem proving. Prolog for example is one of the programming languages in the logic family. It was first developed in the early 1970s by Alain Colmerauer and Phillippe Roussel in the Artificial Intelligence Group at the University of Aix-Marseille. In 1981, the Japanese government launched a large research project to use Prolog as the basis for the effort of developing intelligent machines. The contribution of Prologs participation to logic programming is that it aroused interest in artificial intelligence and logic programming.
Overview of Language
The purpose of the design of a functional programming language is to imitate mathematical functions as much as possible. As a result, functional programming languages approach problem solving differently from methods of imperative languages. They provide a set of primitive functions, a set of functional forms to construct complex functions, a function application operation, and some structures for representing data. They are often implemented with interpreters and occasionally with compilers.
Languages used for logic programming are called declarative languages because programs written in them consist of declarations rather than assignments and control flow statements. One of the essential characteristics of logic programming languages is their semantics, which is called declarative semantics. The basic concept of this semantics is that there is a simple way to determine the meaning of the each statement, and it does not depend on how the statement might be used to solve a problem. Declarative semantics is considerably simpler than the semantics of the imperative languages.
Handling of Data Objects
In functional language, lexical scoping and first class handling are used to handle data objects. Objects are dynamically allocated in a heap and retained until no longer needed. In Scheme, objects are considered first-class data values since they are heap allocated and retained indefinitely. They may be passed freely to procedures, returned as values from procedures and combined to form new objects.
The approach of logic programming on the other hand is to use as a database a collection of facts and rules that state relationships between facts, and to used an automatic inferencing process to check the validity of new propositions. Because it has its basis in predicate calculus, its data objects contains a database of predicates, rule statements and facts. Prolog is the most widely used logic programming languages.
Handling of Sequence Control
Functional programming languages like Scheme and LISP have implicit simple sequence control structure. In Scheme, the order of the procedure and argument expressions evaluation is unspecified. It may be left to right, right to left or some arbitrary order. However, evaluation is guaranteed to be sequential. In Functional languages, execution can be carried out concurrently while Logic-Based languages execute the result-oriented statements or goals in a linear fashion.
Logic based programming languages consist of declarations rather than assignments and control flow statements. But still decision statements exist in logic group. In Prolog, sequence control offers a term call backtracking. Its objective is to obtain a particular goal, which automatically do the backtracking to find the solutions. This method is different from the functional languages because prolog users logic statement and structures. LISP iterative processes are specified with recursive function calls. Compared to the other group, there is a specific sequence method to do the iterative processes and therefore, LISP does not require any loops sequence.
Handling of subprograms and sequence control
The functional language family supports subprograms in the form of both functions and procedures to perform instructions or to return values. It supports built in data types, user defined types as well as static and dynamic types. Functional languages allow functions to have arguments of various types. The logic-based family is a very high-level language, which takes the details away from the programmer. Logic based family blend data and procedures together into program statements called predicates. Procedures are often recursive in logic based and include some built in predicates. Both functional and logic based subprograms are often recursive, but in prolog an indefinite loop is harder to detect since it doesnt follow step by step instructions.
Storage management in functional and logic-based languages is different. The functional language supports automatic garbage collection by the compiler. Once a pointer or other storage becomes deallocated then the data is automatically put back on the heap. In logic based the programmer does not need nor have the ability to implement any storage management techniques. Prolog does not have dynamic storage allocation. ML has automatic garbage cleanup.
Abstraction and Encapsulation
Both the language groups Functional and Logic are not very strong in Abstraction and Encapsulation compared to groups like Object Oriented languages. Functional languages make encapsulation and abstraction possible through the use of structures. The language relies heavily upon simple data types and therefore has no great need for ADTs. The primary data structure used in LISP is a linked list structure. In ML a functional language, constructs are used to create structures or signatures. Structures and signatures make encapsulation and information hiding possible in a functional language.
Logic-based languages generally support no real abstraction because complex data structures are actually based on simple data structures of atomic prepositions, while lists provide some kind of abstraction. The only encapsulation found in Logic Based Languages is through the use of selectors and lists. Structures provide a greater degree of abstraction.
Sebesta, Robert W. Concepts of Programming Languages. Berkeley: Addision-Wesley Longman, Inc., 1999.