Project 4
1 Object-Based and Functional
History
Object-Based Programming Languages
SIMULA I (1962-65) and Simula 67 (1967) are the two first object-oriented languages. The Simula languages were developed at the Norwegian Computing Center, Oslo, Norway by Ole-Johan Dahl and Kristen Nygaard.
Simula concepts have been important in the discussion of abstract data types and of models for concurrent program execution, starting in the early 1970s. Simula 67 and modifications of Simula were used in the design of VLSI circuitry (Intel, Caltech, Stanford). Alan Kay's group at Xerox PARC used Simula as a platform for their development of Smalltalk (first language versions in the 1970s), extending object-oriented programming importantly by the integration of graphical user interfaces and interactive program execution. Bjarne Stroustrup started his development of C++ (in the 1980s) by bringing the key concepts of Simula into the C programming language. Simula has also inspired much work in the area of program component reuse and the construction of program libraries. Although SIMULA 67 never achieved widespread use and had little impact on the programmers and computing of its time, support for object-oriented programming is now part of most popular imperative languages, including Ada 95 (AARM, 1995), Java, and C++.
C’s ancestors include CPL, BCPL, B, and ALGOL 68. CPL was developed at Cambridge University in the early 1960s. BCPL is a simple systems language developed by Martin Richards in 1967. B was designed and implemented by Thompson in 1970. Neither BCPL nor B is a typed language. Being untyped means that all data are considered machine words, which leads to many complications and insecurities. This problem, along with several others, led to the development of a new typed language based on B. Originally called NB but later named C; it was designed and implemented by Dennis Ritchie at Bell Laboratories in 1972. ALGOL 68 also influenced C. C has adequate control statements and data-structuring facilities to allow its use in many application areas. It also has a rich set of operators that allow a high degree of expressiveness.
Smalltalk is a pure object-oriented language – everything is an object an all computation is accomplished through message passing.
A new version of C named C++ was developed in the middle and late 1980s. The first step from C toward C++ was made by Bjarne Stroustrup at Bell Laboratories in 1980. C++ builds language facilities on top of C to support much of what Smalltalk pioneered. C++ has evolved from C through a sequence of modifications to improve its imperative features and additions to support object-oriented programming.
The most essential part of support for object-oriented programming is the class/object mechanism, which originated in SIMULA 67 and is the central feature of Smalltalk. C++ provides a collection of predefined classes, along with the possibility of user-defined classes. The classes of C++ are data types, which, like Smalltalk classes, can be instantiated any number of times.
Functional Programming Languages
A number of functional programming languages have been developed. The oldest and most widely used is LISP. McCarthy and Marvin Minsky formed the MIT AI Project, with funding from the Research Laboratory for Electronics, in the fall of 1958. The first important effort of the project was to produce a system for list processing. This application became the impetus for the development of the list-processing language LISP. The first version of LISP is sometimes called pure LISP because it is a purely functional language. LISP is still the most important of the functional languages, at least in the sense that it is the only one that has achieved widespread use.
LISP has two descendants: COMMOM LISP and Scheme. The Scheme language emerged from MIT in the mid-1970 (Sussman and Steel, 1975). Scheme is a small, static-scoped dialect of LISP. Scheme is well suited to educational applications.
COMMON LISP (Steele, 1984) was created in an effort to combine the features of several dialects of LISP developed in the early 1980s, Including Scheme, into a single language. COMMON LISP is a large and complex language.
ML (MetaLanguage) was originally designed in the 1980s by Robin Milner at the University of Edinburgh as a metalanguage for a program verification system named Logic for Computable Functions (LCP) (Milner et al., 1990). ML is primarily a functional language, but it also supports imperative programming. ML is a strongly typed functional language with more conventional syntax than LISP and Scheme.
Miranda was developed by David Turner at the University of Kent in Canterbury, England, in the early 1980s (Turner, 1986). Miranda is based partly on the languages ML, SASL, and KRC.
Haskell (Hudak and Fasel, 1992) is based in large part on Miranda. Haskell is one of the newest ``big'' functional languages. Haskell is notable for making no compromises on functional purity -- there are no side-effecting operations in Haskell. Haskell also uses an interesting evaluation strategy called lazy evaluation. Haskell is partially based on ML but is a purely functional language.
Object-Based Programming Languages vs. Functional Programming Languages
Object-Based Languages came later than the Functional Programming Languages. Functional Programming Languages arose from LISP in the 1958, and Object-Based Languages has its roots in SIMULA 67 but was not fully developed until the evolution of Smalltalk resulted in producing Smalltalk 80 in 1980.
Object-Based Programming Languages
Object orientated programming had several specific design goals. One major need of object orientation was to control embedded computer systems (such as radar installations) as well as traditional application software. The software produced would also have to be maintained and modified easily. To do this, object orientation incorporated many software-engineering techniques new at that time as well as stressed readability over write-ability.
A language that is object oriented must provide support the three key language features: abstract data types, inheritance, and a particular kind of dynamic binding.
Abstraction is a view or representation of an entity that includes only the attributes of significance in a particular context. Abstraction allows one to collect instances of entities into groups in which their common attributes need not be considered. These common attributes are abstracted away. This results in significant simplification of the elements in the group. The best opportunities for Abstraction were in software reuse. Abstract data types, with their encapsulation and access controls, were obviously the units to be reused.
Inherence offers a solution to both the modification problem posed by abstract data type reuse and the program organization problem. If a new abstract data type can inherit the data and functionality of some existing type, and is also allowed to modify some of those entities and add new entities, reuse is greatly facilitated without requiring changes to the reused abstract data type. Programmers can take and existing abstract data type and mold it to fit a new problem requirement.
Dynamic binding is supported by allowing one to define polymorphic variables of the type of the parent class that are also able to reference objects of any of the subclasses of that class. One purpose of this dynamic binding is to allow software systems to be more easily extended during both development and maintenance. Dynamic binding through polymorphic variables is a powerful concept.
All computing in a pure object-oriented language is done by the same uniform technique: sending a message to an object to invoke one of its methods. A reply to a message is an object that returns the value of the computation of the method.
The essence of object-oriented programming is solving problems by identifying the real-world objects of the problem and the processing required of those objects, and then creating simulations of those objects, their processes, and the required communications between the objects.
Object-oriented programming offers a new and powerful model for writing computer software. Objects are "black boxes" which send and receive messages. This approach speeds the development of new programs, and, if properly used, improves the maintenance, reusability, and modifiability of software.
Functional Programming Languages
The functional programming paradigm, which is based on mathematical functions, is the design basis for one of the most important nonimperative styles of languages. This style of programming is supported by functional, or applicative, programming languages.
The objective of the design of a functional programming language is to mimic mathematical functions to the greatest extent possible. A purely functional programming language does not use variables or assignment statements to produce results; rather they use functional applications, conditional expressions, and recursion for execution control, and functional forms to construct complex functions.
Without variables, the execution of a purely functional program has no state in the sense of operational and denotational semantics. The execution of a function always produces the same result when given the same parameters. This is called referential transparency. It makes the semantics of purely functional languages simpler.
A functional language provides a set of primitive functions, a set of functional forms to construct complex functions from those primitive functions, a function application operation, and some structure or structures fro representing data. Theses structures are used to represent the parameters and values computed by functions. A well-defined functional language requires only a small number of primitive functions.
Although functional languages are often implemented with interpreters, they can also be compiled.
Object-Based Programming Languages vs. Functional Programming Languages
With Object-Based Programming Languages, an expression is evaluated and the result is stored in a memory location, which is represented as a variable in a program. This necessary attention to memory cells results in a relatively low-level programming methodology. A purely Functional Programming Language does not use variables or assignment statements. This frees the programmer from concerns about the memory cells of the computer on which the program is executed.
Functional Programming Languages can have a very simple syntactic structure. The list structure of LISP is an example. The syntax of Object-Based Programming Languages is much more complex. The semantics of Functional Programming Languages can also be simple compared to that of Object-Based Programming Languages.
Handling of Data Objects
Object-Based Programming Languages
Object-Based Programming Languages support data types such as Integer, Decimal, Boolean, Character, records, sequential files etc., at the same time they allow for the creation of abstract data types that can be encapsulated with functions to form an object. Object-Based Programming Languages allow for inheritance. Hierarchy of objects allow the programmers great flexibility because they can call methods on a data object, create more data objects, or assign one data object to another. Also, object encapsulation and inheritance allows for easier imbedding of programming concepts such as projection and security in regards to data objects.
Functional Programming Languages
Functional languages, however, apply different concepts to data types. There were only two types of data objects in the original LISP: atoms and lists. They are not types in the sense that Object-Based Programming Languages have types. In fact the original LISP was a typeless languages. A purely Functional Programming Language does not use variables or assignment statements. The execution of a function always produces the same result when give the same parameters. Most functional languages, such as Scheme, have adapted to allow for basic data types such as integers, real numbers, and characters. A functional language provides a set of primitive functions, a set of functional forms to construct complex functions from those primitive functions, a function application operation, and some structure or structures fro representing data. Theses structures are used to represent the parameters and values computed by functions.
Object-Based Programming Languages vs. Functional Programming Languages
Object-based languages have predefined data types, such as real, integer, character, and Boolean. Most also allow for user-defined data types, and others, such as JavaScript, do not. Object-based languages allow for the creation of abstract data types that can be encapsulated with functions to form an object. These objects allow for inheritance from a parent object to a child object. This hierarchy of objects allow the programmer great flexibility because methods can be called on a data object, more data objects can be created, and assign data objects can be combined. Also, object encapsulation and inheritance allows for easier imbedding of programming concepts such as projection and security in regards to data objects. Concepts such as multiple inheritance and polymorphism, found in only some object-based languages, extent the data abstraction and encapsulation even further by allowing a programmer to create building blocks from objects and calling single methods that will affect various objects in a different manner depending upon their implementation.
Functional languages, however, apply different concepts to data types. Where object based languages allow for abstraction using basic data types such as int and char, pure functional languages are basically typeless. The variable type is not determined during compile time but during evaluation of an expression. Many functional languages, however, have adapted to allow for basic data types such as integers, real numbers, and characters.
Functional languages make use of data structures usually stored as linked lists. Functional languages do not use variables or assignment statements. Functional languages, unlike object-oriented languages, have a very simple syntactic structure. Functional languages employ the use of terms, which are constructed from constants, variables, or structures. Constants are usually integers, variables are strings, and structures can be groups of both. Each term has different rules as to how characters are put together to form its name.
Handling of Sequence Control
Object-Based Programming Languages
Object-based hide information (encapsulation) and use class hierarchy when a class is called in a sequence control; this enhances readability and dependability. Functional doesn’t use class hierarchy concept.
Control flow in mathematical function definitions is quite different from that in Object-Based Programming Languages. Whereas functions in Object-Based Programming Languages are defined as collections of statements that may include several kinds of sequence control flow, mathematical functions do not have multiple statements and use only recursion and conditional expressions for evaluation flow.
Functional Programming Languages
In Functional programming languages, where list structures are the primary data structure available, they
use recursion to control mechanism for repeating sequences of statements. In Object-Base, this is done by array incrementing.
Object-Based Programming Languages vs. Functional Programming Languages
Object-based languages were developed on the imperative language paradigm. That is, instructions are executed sequentially. Basic control structures such as if-then-else statements, conditional loops, and case statements can be used to direct execution to some other part of the program. When this other part of the program is reached, execution continues in sequential order until told to do otherwise by another control statement. Precedence of operators is given left to right, and arithmetic and logical operators have an hierarchy of precedence. Object-based languages force sequence control with the use of parentheses and creates blocks with the use of brackets.
Sequence control in functional languages, on the other hand, is defined using the model of mathematical functions. Control flow in mathematical function definitions are quite different from those in object-based programming languages. Functions in object-based languages are defined as collections of statements that include several kinds of sequence control flow. Mathematical functions do not have multiple statements and use only recursion and conditional expressions for evaluation flow. Functional languages use recursion to do repetition, while object-based language use iteration.
An excellent example for contrasting the languages is the factorial function. In an object-based language, as in all imperative languages, it would be defined something like this:
int j = 1;
int n;
While (n > 0)
{
j = j*n;
n = n - 1;
}
The same function in a functional language would have a control structure that looks much more like the mathematical function definition factorial using recursion and conditional expressions.
(DEFINE (factorial n)
(IF (= n 0)
1
(* n (factorial (- n 1)))
))
Another important difference between the two languages is in the implementation of functions. Object-based languages may call a function that executes sequentially and returns a value. Functional languages may call a function that may return a value or recursively call another function, which may itself return a value of function call.
Functional language can be executed by first translating them into graphs. These graphs can then be executed through a graph reduction process.
Handling of Subprograms and Storage ManagementObject-Based Programming Languages vs. Functional Programming Languages
Both Functional Programming Languages and Object-Based Programming Languages support subprograms. Both language groups utilize subprograms as a form of information hiding. This allows a programmer to identify error quicker while not worrying about how other functions operate. Heap-dynamic memory allocation is supported because both language groups commonly allow pointer for linked lists and other data structures. Also, most of the languages use "garbage collection" to handle dangling pointers. Moreover, storage de-allocation is used explicitly by the languages when the heap generators are no longer in use. Object-Based Programming Languages employ information hiding by using parent and derived classes. Derived classes are only visible to the parent class, while any changes to a subclass can raise errors in the parent class. Object-Based Programming Languages also support pointers and memory allocation. Some Object-Based Programming Languages only use static type binding, such C and C++. In Object-Based Programming Languages, an expression is evaluated and the result is stored in a memory location, which is represented as a variable in a program. A purely functional programming language doesn’t use variables or assignment statements. This frees the programmer from concerns about eh memory cells of the computer on which the program is executed.Object-based languages encapsulate data and methods into objects. This encapsulation improved on the imperative design of passing control from one section of code to another. Object-based languages allow for methods to be encapsulated so there is more control over the environment in which the program is run. Different objects create different environments so calling the methods of different objects allows for more environmental control.
Object-based languages also support pointers and memory allocation. C++ is an object-based language where the programmer is responsible for deleting memory that is no longer in use. Java supports garbage collection, as functional languages do, where unused memory is re-claimed.
The Object-Based languages use very long and complex subprograms which are essentially small programs in and of themselves that merely work together to form larger programs. Functional programming languages have very simple and small sub-programming capabilities. These subprograms are limited in size and scope, and must be combined efficiently to work together. Pointers are available in some Object-Based languages, but functional languages do not allow direct access to memory.
The programmer is given much control in storage management in object-based languages. The programmer can store data structures, variables, objects, and pointers to all of these. The programmer can create and delete these from memory at will. In pure functional languages, there are no variables so the programmer has little control of storage management. The programmer must use the design of the program to recursively create data structures to manage storage.
Handling of Abstraction and Encapsulation
Object-Based Programming Languages vs. Functional Programming Languages
An abstraction is a view or representation of an entity that includes only the attributes of significance in a particular context. Encapsulation is a precursor of and support mechanism for abstract data types. Object-Based and Functional languages all have some form of abstraction and encapsulation. Object-Based languages however are much more versatile in their ability to do either.
Abstraction is one of the most important features of Object-Based Programming Languages. Object-Based Programming Languages make use of abstraction by utilizing abstract data types and prototyping. Functions and subroutines can be encapsulated to ensure the security of values that are being passed from function to function. Features of a child class can be passed to a parent class through the use of inheritance. In fact pure object-based languages are nothing but classes, everything is abstracted into a class object.
Functional languages however are not as versatile as Object-Based Programming Languages. Functions or Modules are also used in Functional languages, which may be compiled in separate files. A functional language provides a natural abstraction mechanism, with implementation hiding being performed by closures. The danger is that in adding bells and whistles we will destroy abstraction (e.g. pattern matching in ML).
Object-based languages improved on other imperative languages for allowing the encapsulation of data and methods in to objects. This allows for the representation of real world objects and the handling of complex real world problems. This is the language group's defining characteristic. This high level of abstraction allows for inheritance of objects and, therefore, greater ease in imbedding programming concepts such as protection and security. The abstraction can be used to allow for multi-platform software or modeling of real problems in software. In object-based languages, encapsulation hides details of an object from the programmer. For example how a certain object is implemented is hidden from the programmer, and only the knowledge of what methods to call to get the desired result is necessary. C++ provides different levels of this through the convention of using public, protected and private data and methods.
Functional languages do not support true abstraction. Most functional languages support information hiding, but that’s the extent of encapsulation and abstraction. They do not have advanced data types. They rely heavily upon simple data types and therefore have no need for abstract data types. However, functions in themselves are abstractions because their inner workings are hidden from the view of the other functions and the programmer. The function "objects" work together with each other in a program to complete a task. In this way, functional language provide for abstraction where object-based languages concretely abstract typed data and methods.
2 Object-Based and Logic
History
Object-Based Programming Languages vs. Logic Programming Languages
In the early 70's, the Department of Deense was using many programming languages. On top of that, some of the languages had several, incompatible versions. The Department of Defense realized that the cost of developing and maintaining the software produced by the multitude of languages was rising dramatically, which lead to object based programming languages. In an effort to curb the rising costs, the DoD formed the Higher-Order Language Working Group. Their task was to come up with a single programming language designed to meet the all the needs of all branches of the military. Ada was one of the products of their efforts. Logical Programs are to do much of current theoretical value comes from important extensions, modifications and experimental aspects. These include: Constraint logic programming (CLP) Parallelism and concurrency Linear logic (LLP) Inductive logic (ILP) Committed Choice Languages Higher-Order Logic (HOL) Object-oriented programming (OOLP). Many of these extensions include or relate to OO abilities. Some go beyond traditional OO.
Logical languages were developed for linguistics and artificial intelligence research. They are based on a form of logic called predicate calculus. In logical languages it is the system, not the programmer who decides how a calculation will be carried out. In other words, the programmer will ask for validation of a statement based on the given bank of data. This data is assumed to be true. If the given data can validate the query, a positive result is returned. If not, a negative result is the response. In logical programming the steps of how an answer is to be generated is taken out of the hands of the programmer. Unlike, Object-Oriented languages, which are imperative, Logic languages are declarative in nature. They are used widely in artificial intelligence applications due to their ability to produce smart machines. Logic based languages are generally used in four areas: Relational Database Management Systems, Expert Systems, Natural Language Processing, and introducing children to logic and computers.
Object-Based Programming Languages vs. Logic Programming Languages
Object orientated programming had several specific design goals. One major need of object orientation was to control embedded computer systems (such as radar installations) as well as traditional application software. The software produced would also have to be maintained and modified easily. To do this, object orientation incorporated many software-engineering techniques new at that time as well as stressing readability over write-ability, Ada and C++ is object-based languages. Logical Programs area goal-oriented, implicative language based on predicate logic. Goal-oriented means that a program proceeds by attempting to achieve a goal, which is it, self defined by other goals. Prolog, an example of logical programs, operates in an inferential or implicative way: what you write are implications, and the operational flow is from one implication to another. A line of Prolog code is generally either a rule or a fact - code and data being largely interchangeable. Prolog code often has a declarative interpretation, meaning that it specifies "what" exists but not "how." This is different from imperative in which a program defines a series of steps to carry out (C or Basic for example). EXAMPLE: PROLOG means PROgramming in LOGic.
Logical Programs area goal-oriented, implicative language based on predicate logic. Goal-oriented means that a program proceeds by attempting to achieve a goal, which is it, self defined by other goals. Prolog, an example of logical programs, operates in an inferential or implicative way: what you write are implications, and the operational flow is from one implication to another. A line of Prolog code is generally either a rule or a fact - code and data being largely interchangeable. Prolog code often has a declarative interpretation, meaning that it specifies "what" exists but not "how." This is different from imperative in which a program defines a series of steps to carry out.
Handling of Data Objects
Object-Based Programming Languages vs. Logic Programming Languages
In Object-Based languages, the concept of inheritance (and mutiple inheritance) is practised. It allows a new abstract data type to inherit all the data and functionality of some already existing type. In this way, the programmer has the ability to add, delete or modify an existing type over and over again in a program. This greatly facilitates reuse in programs and makes coding easier and quicker.
Object-Based languages have pre-defined data types, such as real , integer, character, and boolean etc. Most object-based languages such as C++ and Eiffel allows for user-defined data types. java-script however, does not. In the Object-Based language group, the concept of classes is also used, although it is not the primary data type. It extends the built-in capabilities of the languages to assist in the representation and solving complex, real-world problems. Classes are an additional element to standard data typing and are typically comprised of a number of primary data types.
On the other hand, Logic-Based languages allow the use of terms, which are constructed from constants, variables, or structures. All three are different, as in constants are usually integers; variables are strings; and structures can be groups of both. Each term has different rules as to how characters are put together to form its name. Prolog also supports simple arithmetic.
Data objects are a fundamental part of object-oriented languages. In procedural languages, there are built-in data types from which user defined abstract data types can be constructed. In object-oriented languages everything from data to procedures is part of an abstract type usually known as a class. First, the structural definition of a class is created, including all its member variables and procedures. These are bound together in the definition of the class. Then instances of the class are defined just as instances of types are defined in procedural languages. As stated. The power of object-oriented programming languages is the ability to reuse and modify these class structures to define new classes.
In logical languages, data is divided into facts, such as "1 is an integer", and rules such as "Integer (X) :- Integer (Y), Integer (Z), Subtract (X,Y,Z)". The meanings of the rules are arbitrary and rely on the programmer to define them. For example, this previous rule could mean that X is an integer if Y and Z are integers, and X is the result of Y-Z. This type of logical statement is called a HORN clause. It is important to note that by the rule it can be verified that X is an integer if Y and Z are, but we cannot verify if X is not an integer. Logic languages do not make use of even some of the basic types used in object-based languages, such as arrays and records. In no manner do they support the concept of classes.
Handling of Sequence Control
Object-Based Programming Languages vs. Logic Programming Languages
Object-oriented languages have conditional control structures and linear execution of code like their procedural predecessors. The primary difference between object-oriented and procedural control structures is that all subprograms in an object oriented language are encapsulated with the class they are associated with. In other words, in order to add two integers, the add function of the class integer is called. Indeed, the conditional controls themselves may be nothing more than class operations. For example, Smalltalk provides an object called a block that can contain procedure calls on objects, also known as messages. The messages within a block are only executed when the block member function value is called. Other member functions like whileTrue: and timesRepeat create iterative structures for Smalltalk. For example a logical loop statement would be written:
counter<-0.
sum<- 0.
[counter < 20] whileTrue: [<loop body>. counter <- counter + 1]
In a true logical languages, the programmer has no influence over how the program executes. He/She can ask questions of the supplied data which the system systematically tries to validate. A positive or negative response is returned dependent upon the findings. Logical operators such as AND, NOT, and OR are available to create logical phrases. For example if a query, Integer (-2) was asked, the system might first check it's data to see if -2 has been defined as an integer. If not, then it would have to use the rules present in the system to try and determine if -2 is an integer. With the data and rules for the previous section, the process might go something like this.
Integer (-2) not found in facts.
Find rules that resolve to Integer
Integer (X) :- Integer (Y), Integer (Z), Subtract (X,Y,Z)
Find facts that can substitute for each of the statements on the right hand
side.
Integer (X) :- Integer (1), Integer (1), Subtract (0,1,1)
Since X does not resolve to -2 on the right hand side, replace X or Y
This process continues until a values for X and Y are found such that Subtract (X,Y,Z) is true or until all possible facts and rules that could possibly substitute for X and Y are exhausted. If a combination such as:
Integer (X) :- Integer (2), Integer (4), Subtract (-2, 2, 4)
is found, the query will return true. If the data and rules are exhausted and no such combination can be found, the query is false. As you can see if we have a large database, their can be many steps to solve even a simple query. Likewise in the above example, the definition for integer is recursive. The search could expand to:
Integer (X) :- (Integer (Y1):-(Integer (Y2):-(Integer (Y3) ... (Integer (Yn))))),
Integer (Integer (Z1):-(Integer (Z2):-(Integer (Z3) ...
(Integer (Zn))))),
Subtract (X,(Integer (Y1):-(Integer (Y2):-(Integer (Y3) ... (Integer (Zn))))),
(Integer (Z1):-(Integer (Z2):-(Integer (Z3) ... (Integer
(Zn))))))
In a strict logical language, the programmer has no control over how the validity of the query is determined, however if the programmer is familiar with the data and rules and how the queries are executed, he/she may optimize the query. For example, if verification of the terms in the right hand side is in order, the term it takes the least time to verify as false could be listed first.
Object-oriented languages have conditional control structures and linear execution of code like their procedural predecessors. The primary difference between object-oriented and procedural control structures is that all subprograms in an object-oriented language are encapsulated with the class they are associated with. In other words, in order to add two integers, the add function of the class integer is called. Indeed, the conditional controls themselves may be nothing more than class operations.
In true logical languages, the programmer has no influence over how the program executes. Instead, queries are made and the supplied data is used by the system in an attempt to validate the query. A positive or negative response is returned dependent upon the findings. Logical operators such as AND, NOT, and OR are available to create logical phrases. For example if a query, Integer (-2) was asked, the system might first check it's data to see if -2 has been defined as an integer. If not, then it would have to use the rules present in the system to try and determine if -2 is an integer. Although the programmer has no control over how the validity of the query is determined, if he is familiar with the data and rules and how the queries are executed, the query may be optimized. For example, if verification of the terms in the right hand side is in order, the term it takes the least time to verify as false could be listed first.
Handling of Subprograms and Storage Management
Object-Based Programming Languages vs. Logic Programming Languages
Logic based languages don't allow the use of functions or procedures. Details of the program are hidden from the programmer and stored into statements called predicates. Object-based programming makes use of information hiding. This language makes use of parent classes and derived classes. Derived classes are only visible to the parent class, while any changes to a subclass can raise errors in the parent class. The programmer is not required to implement storage methods. Languages in both groups do this automatically. Low-level manipulation is possible in object based languages.
In Object oriented languages, subprograms are an integral part of the data types. Class definitions contain data elements and the operations on those elements. The subprograms of an object have objects as a return type. Likewise, if the subprogram has parameters, the parameters may be subprograms that return objects. Often data elements of a class are given some level of security, and may only be modified through the class member procedures. Instances in object-oriented languages can be statically or dynamically allocated on the run-time stack, or the heap. Of course if an object is statically allocated, there is an advantage in execution speed. Creating all objects dynamically simplifies referencing, but requires us to decide if such objects are explicitly or implicitly deallocated. By it's very nature, object-oriented languages require the ability to dynamically bind messages and methods to allow for polymorphic expressions. But if we are allowed to declare which method is to receive a message statically, we can increase execution speed.
Logical languages define relationships rather than procedures. A logical relationship or rule states that if certain conditions are met, a new fact is implied. For example, if it is given that spot is a dog and there is a rule that states "if X is a dog than X is a mammal", we can derive that spot is a mammal. Because spot may have many relationships other than dog defined for it, we must have a flexible structure so that queries can be answered as efficiently as possible. There are two choices, either the instance may be shared by all relationships, or multiple instances of the same value may be created for the relationships. Copying is faster for evaluating queries, but sharing takes less memory. In order to maximize efficiency, an implementation can use a combination of techniques.
Handling of Abstraction and Encapsulation
Object-Based Programming Languages vs. Logic Programming Languages
Object-Based and Logic Based languages both have a high level of abstraction and encapsulation, but are very different in how and what is done. Object-Based languages encapsulate almost everything in a class and define abstract data types to represent real world objects. The programmer has full control as to how and what is abstracted and encapsulated. Logic Based languages achieve abstraction by the nature of the language. The programmer tells the program what to do but not how to do it; this in essence is abstraction. Lists are used by some Logic languages, which are an abstract structure. Some languages also use selectors to achieve a form of encapsulation; they allow parts of an object to be read.
It is the approach of Object oriented languages to defining and accessing abstract data types that gives them their flexibility. In a purely object-oriented language, all data is stored in objects, and there is no distinction between language and user defined objects, or classes as they are more commonly called. In addition, object oriented languages allow new classes to inherit all the characteristics, procedures, data elements of one or more existing classes. To this base structure, new elements and procedures may be added. As long as the type checking rules of the language are not violated, existing procedures may be rewritten to make for changes in the new class. This flexibility allows data structures to be created from what is known as a class hierarchy. Similar objects can be created by inheriting the code of a parent class. It also allows for polymorphism, where a pointer or reference to a parent call can point to or be filled with an instance of any classes that have inherited the parent's data structure. This paradigm allows for reuse and modification of existing code along with dynamic binding of objects sharing a hierarchy.
A rule in a logic language is nothing more than an encapsulation of data. A single rule may imply thousands or even millions of possible facts. Likewise, modules of facts and rules can be encapsulated and imported into programs. Both object-based and logical languages support abstraction and encapsulation through the use of modules. Each of them allows for multiple blocks of code to be compiled separately and used with other blocks of programs. An object-based language’s encapsulation can be provided with a precompiled module or capsule known as a library. Most object-based languages provide support for encapsulation through the use of libraries. In a logical based language the programmer needs to supply information following a set of rules, and ask questions - not worry about the ways the rules must be applied to answer these questions.
Reference
Web Sites
Declarative Programming: The Prolog Language. 10 Apr. 2001.
http://www.cosc.canterbury.ac.nz/~wolfgang/cosc302/Chap2.4.html#history
Kifer, Michael, Lausen, George, Wu, James. Logical Foundation of
Object-Oriented and Frame-Based Language. 10. Apr. 2001.
http://citeseer.nj.nec.com/kifer90logical.html
The Scheme Programming Language. 10 Apr. 2001.
http://www.engin.umd.umich.edu/CIS/course.des/cis400/scheme/scheme.html
Toni, Klazic. What are Logic Programming and Prolog? 19 Apr. 2001.
http://www.ibc.wustl.edu/moirai/cs_magenta/prolog.html
Object-Oriented Languages: A Comparison. © 1993-2001 Interactive
Software Engineering.
http://www.eiffel.com/doc/manuals/technology/oo_comparison/index.html
An Eiffel Tutorial. 2001.
http://www.eiffel.com/doc/online/eiffel50/intro/language/tutorial-00.html
Eiffel In a Nutshell, 2000.
http://www.eiffel.com/eiffel/nutshell.html.
Johnson, Stephen C. YACC: Yet Another Compiler Compiler. AT & T
Bell Laboratories.
http://www.cs.uaf.edu/~cs631/yacc-docs.txt
Darwin, Ian. A History of UNIX Before Berkeley: UNIX Evolution, 1975-1984.
1984.
http://www.daemonnews.org/199903/history.html
Scheme: The Scheme Programming Language. 1999.
http://www.engin.umd.umich.edu/CIS/course.des/cis400/scheme/scheme.html
Kelsey, Richard. Scheme: Revised Report on the Algorithmic Language Scheme.
2001.
http://www.swiss.ai.mit.edu/~jaffer/r5rs_toc.html
Stone, John D. Fundamentals of Computer Science I.
http://www.math.grin.edu/courses/Scheme/
Bugrim, A., Fabrizio, F., Feng, B., Holcomb, J., Sawa, F., Slomczynski, J. ,
Wise, W. , Kazic T. What are Logic Programming and Prolog? Klotho:
Biochemical Compounds Declarative Database.
http://www.ibc.wustl.edu/moirai/cs_magenta/prolog.html
Sedlick, D., 2000. Prolog Say What? Discussion.,
http://www.franken.de/users/nicklas/das/papers/prolog_description/discussi.html
Prolog Development Center. Visual Prolog, How Does Prolog Differ from
Other Languages?
http://www.visual-prolog.com/viptechinfo/pdcindex.htm
Henderson, F., Conway, T., Somogy, Z., Jeffery, D., Schachte, P., Taylor, S., Speirs, C. 1995-2001. Mercury Project. University of Melbourne. http://www.cs.mu.oz.au/research/mercury/index.html
Becket, R. Mercury Tutorial.
http://www.cs.mu.oz.au/research/mercury/tutorial/index.html
Books
Ole-Johan Dahl and Kristen Nygarrd, How Object-Oriented Programming Started.
Thomas Dunn, Principles of Object Oriented Programming
Robert W. Sebesta, Concepts of Programming Languages