Unique Feature #2

There was a second feature that I mentioned using within the language of Prolog. The second unique feature I did was bagof, setof, and findall. This feature deals with finding specific relations being pulled from lists of information created in WordPad and retrieved in SWI-Prolog. To create an example for this, I used my own data by creating relations of family members in my family. I created a list of members with names of my family and what their relation to me. Here is what the list looked like:

unique2

Now to test the unique feature I used this set of code after using the consult method in SWI-Prolog:

unique1

To explain what I tested here, I first used bagof to retrieve the list of names of all of my aunts. If we remember, bagof collects a list bag of all the list items for some goal. On the third line I do not specify the member to that I wished to retrieve. The program output what member it was retrieving, aunt, and then output the names of all of my aunts. On line four I executed the same goal as I did for line one, but this time requesting the names of all of my uncles. On line five I did not specify what bag of items I wished to retrieve, but instead I asked for just the list of all the names in my family. The output was a printed list of all the names I put into the WordPad list. Line six is where I began to use setof. If we remember, setof means that we are binding set to the list of all the instances of the list to satisfy the goal requested by the user (source). On line six, I used an example from the book, Prolog: Programming for Artificial Intellegence. What I did here was request to see all of the member names within the list I created. Then I asked for the specific types of members that were available in the list using the term, MemberList. On line seven, I used setof to output the Member type/the name of the member. To do this, I used a “/” to divide the the member type and name. Finally, I used the finall method. If we look back, findall means that we are collecting all of the items from a list to reach a goal. Her is what I did. I used findall to find the names of all of the members who were my mom. Well considering I only have one mom, it output the name of my mom, Suzanne.

The sources I used for this post was Prolog: Programming for Artificial Intellegence by Ivan Bratko and http://www.cse.unsw.edu.au/~billw/prologdict.html#findall

Unique Feature Program #1

In the previous blog I discussed two features of Prolog that were unique, and unlike any other feature of a programming language. The first feature I will show a small program on is a binary tree diagram. To recap, tree diagrams test whether X is a member of the list.

If we begin with binary trees in Prolog, we can look at the previous information given to see that rules to creating binary trees can be written in code. For example, the previous post explained how X is a node that is part of a tree T if the root of T is X, or X is in the left or right subtree of T. To show this, we can use the code:

 

binarytree

The code allows us to see how the “in” relation rules work. Let’s look at an example to support this rule of binary trees:

finaltree2

This example of binary trees does not use the “in” relation. I found a hard time implementing it into my program so instead I took it out and simplified the program to just using what was mentioned in previous examples. I implemented node, X, L, and R into the program to visually show the unique feature. To execute this I tested a few executions:

finaltree

In this example, in line one, I call the WordPad file by using consult, which was followed by the output true. On line two, I asked if there was not a root for 3, and there was an output of false. For lines three and four, I input what a binary relation looked like:

t(t(nil,b,nil)a,t(t(nil,d,nil),c,nil))

What I explained in my previous post was that “nil” represents the empty tree. Instead of using nil, I used the word empty to see if this would work and it did. I believe that the words are interchangeable. For the fifth line, i accidentally used the wring syntax, so the program output where my error occurred. Finally on the sixth line, I attempted to repeat what I did in line five. This time with the correct syntax I received the output of false. This is because I stated at the end of the clause that 0 was a root of 4, 3, and 6. This statement is false so that would produce an output statement of false for the program. Lines three and four show that the numbers put at the end of the clauses are roots of the numbers given.

For this post, the sources I used were:

Click to access 19Prolog4.pdf

and Prolog: Programming for Artificial Intellegence by Ivan Bratko

Unique Features of Prolog

Binary Trees

When using lists of data, which are sets of objects, it is inefficient to scan a list for a specific element if the list is very long. What Prolog efficiently does is uses tree structures to show relations. If we look at the structure of a binary tree structure. This type of structure is either empty or it holds a root, a left subtree, and a right subtree. A root is permitted to be anything but the subtrees must be binary trees. For example, lets look at a list of data {a,b,c,d}.The basic way to represent this binary tree, we can use a specific symbol to be the empty tree, and a functor will construct a non-empty tree from the three elements, the root, the left subtree, and the right subtree. (a functor is the name of the relation and its arguments).

The functor will be t, where the root of the tree is X, the left subtree is L, and the right subtree is R. The functor is represented by the term t(L,X,R). An atom, nil, represents the empty tree. The example of the list of data {a,b,c,d} is represented by the term:

t( t(nil,b,nil), a t( t(nil,d,nil), c, nil))

Now if we look at the members in the set of letters, the relation is named by the word in. The term in(X,T) is true if X is a node in a tree T where the root of T is X, or X is the left or right subtree of T. The list of letters is represented by the tree figure T. The term in(X,T) searches through the list of letters through a method called backtracking where X = a, X = b, X = c, and X = d. If we look at the goal, in(a, T), it will succeed because of the first clause of the procedure in. There will be multiple recursive calls though for finding the object d  in  in(d,T). Something that is made a goal such as in(e,T) will be searched for by the entire tree but then fails because of the recursive searches through the subtrees.

A higher efficiency of this method can be reached by setting an order from left to right. For example: t(Left, X,Right). This means that the nodes on the left subtree are smaller than X, the nodes on the right subtree are greater than X, and both of the subtrees are ordered from biggest to smallest value.

bagof, setof, and findall

Just by looking at previous blogs you can see that you are able to produce all the objects that satisfy one goal. Although this is true, you can only produce an object one by one, and each time a new object is produced, the previous one disappears. These unique features to Prolog allow you to generate all of the objects at once so that the user is able to see them all together. An example of this would be trying to see all of the objects that are part of a list.  Prolog has “built-in predicates,” bagof, setof, and findall, that allow the user to complete such requests.

Let’s take the example:     bagof(X,P,L)

This will produce the List L of all the objects X, where the goal P is satisfied. X and P though have to have variables in common. A real life example can go something like this with facts within a program.

gender(george,male).

gender(karen,female).

gender(frank,male).

gender(suzy,female).

To retrieve the list of all the people who are female you would write this goal:

?-bagof(Child, gender(Child,female),List).

List = [karen,suzy]

Let’s say we did not specify a specific gender to the goal request. Through the process of backtracking, we would receive two lists of those who are female and those who are male. An unspecified version would go like this:

?- bagof(Child, gender(Child, Gender), List).

The results here would be:

Gender = male

List = [george,frank];

Gender = female

List = [karen, suzy];

no

What if want all of the children in one list no matter their gender. We are strictly looking for if the value exists in the list.

?- bagof( Child, Gender ^ gender(Child, Gender), List).

List = [george, karen, frank, suzy]

The ^ is known as a predifined infix operator. Also, let’s say there is no solution for the goal P, this leads to simply the goal to fail. If an object occurs multiple times, them the all the times it occurs will appear in the list of L objects (there will be duplicates of the items).

Now, let’s look at the predicate setof. It is very similar to bagof:

setof( X, P, L)

The predicate setof is different than bagof because it does two things differently. One, the objects in list L will be ordered, and two, if there are any duplicated items, they will be eliminated and produced once. The ordering of the objects is based on an alphabetical ordering system or to the relation “<,” where the objects in the list are numbers. Let’s think about if the objects are structures. This means that the principal functors are compared for ordering. If the functors are equal, then the left-most, top-most functors take precedence.

Let’s use the same gender example as bagof.

?- setof( Child, Gender ^ gender(Child, Gender), ChildList),

setof( Gender, Child ^ gender(Child, Gender), GenderList).

ChildList = [frank, george, karen, suzy]

GenderList = [female, male]

You can see above how each object in the list is ordered based upon the alphabetical system.

Any object with setof can be used. You can collect the data based upon pairings, such as Gender/Child, which would give the result, for example, [female/karen].

The final predicate, findall is very similar to bagof as well.

findall(X, P, L)

This produces a list of objects in L that will satisfy P. The difference here is that all of the objects X within the list L will be collected not matter the possible difference in solutions for variables in P that are not shared with X. Let’s continue to use the gender example.

?- findall( Child, gender( Child, Gender), List).

List = [ george, karen, frank, suzy]

The reason findall works so well is because if there is an object X that does not satisfy P, the findall will still pass with L = [].

There is a tricky part to this though if findall is not a built-in predicate through implementation, then the programmed must be programmed in a certain way. as always backtracking is used to find all of the solutions for P. As the solution is produced, it is put into the database so that it will not be lost when the user tries to find the next solution. After the solutions have been produced, they must be put into a list and drawn back from the database. All the solutions produced form a “queue,” or a list of data items. After each of the solutions are produced, the list of data items “dissolve.” The end of the queue must be marked by the atom “bottom.” This term is different from the expected solution.

The source used for this blog post is the book: Prolog: Programming Artificial Intellegence by Ivan Bratko pgs 182-184

Prolog Procedures and Binary Searches

 

Prolog is a procedural language. Functions are are represented by procedures in Prolog. Procedures and data are then encapsulated into objects through object-oriented programming. The objects will exchange messages so that the encapsulated procedures are invoked. Pieces of a program in Prolog can be stored in class descriptors that act as methods. In this case, an object may inherit a method from another object. An object has the ability to respond to a message by executing one of the object’s methods. The message being sent though to another object is in fact though a procedural call. Prolog has methods to describe procedures and compute answers to messages.

Objects are represented as relations, where:

object(Object, Methods)

The Object names the object and possibly specifies the parameters, and Methods will be a list of Prolog terms specifying the methods. The list of terms can be facts and rules. These types of relations are not followed by a period as seen in other examples. I am going to use the example of finding the area of a rectangle to describe how methods work. The object is rectangle,  the Object is length, and Methods is width.

object (rectangle(Length, Width).

[(area (A) :-

                                A is Length * Width).

(describe :-

write(‘Rectangle of size ‘).

write(Length * Width)) ] ).

Above, you can see that the object possesses two methods, area and describe. In order to send a message from one object to another we can implement a sending message procedure:

send( Object, Message)

The messages between the objects will describe sides of the rectangle 4 and 3 to then compute the area. The messages are sent through the users side of the program. This is not originally typed in WordPad, but rather by the user in SWI-Prolog.

?- Rec1 = rectangle(4,3).

                send( Rec1, desrcibe),

                  send(Rec1, area(Area)).

                                                           Rectangle of size 4 * 3

Area = 12

Lets look into what is happening above. The first step to occur is that the program retrieves the methods of Object. The program then executes the methods that correspond to the Message.

Another example following the object oriented is finding the sum of a list of numbers. The object is the “[]” and “0” is the message the method sends. The reason this is an object oriented example is because Sum is the sum of numbers in ListOfNumbers:

sum([],0).

sum([Number | Numbers], Sum) :-

sum(Numbers, Sum1),

Sum is Sum1 + Number.

The output to this piece of code is:

sumpic

A third example that will follow the object-oriented programming style is making a list of numbers and seeing how many times the number occurs in the list (N times). This example follows the same rules as the previous two examples:

makelist(_,0,[]).

makelist(Item,N,[Item|List]) :-

N > 0, N1 is N -1,

                makelist(Item, N1, List).

The output for this program is:

listitempic

Binary searches are very interesting when it comes to finding a specific item from a list that is already sorted or arranged. Prolog has an interesting way of finding a list item in the middle of the list, the beginning, or the end. Because Prolog is a recursive language, a program with a binary search will find a value at a given index by the user and recursively remove the head of the list (first value), and decreases the index until all the values in the front of the list are taken out. This process uses the list as a constant in the program.

This is an example of a binary search I have from https://wiki.colby.edu/display/LPE/Prolog+Binary+Search I thought really helped to explain how binary searching worked in Prolog :

binarysearch2

Above is the code written in WordPad. This program will check to see if a value in a list given by the user in SWI-Prolog is an integer. Because Prolog is non-deterministic, the user can find different paths to find a true statement. The first statement: contains(List, Value):- even_division(_, [Value|_], List).  tries to find the value of the middle number in the given list. The second piece of code then tries to find if the list has a value that is larger than the middle number of the list, and that the second half of the list will contain the center number. This provides the first half of the numbers to the list. The third piece of code shows that the value of the second half to the list. If the value in the list of the numbers is smaller than the center number, the first half of the list is shown to contain the value of the center number. The third set of code determines that the statement provided by the user is true ” if X is the concatenation of the first part of the list and second part of the list and the first and second part of the list are either the same length or the second part is one element longer than the first element. If the second part of the list is one element longer, then it will be printed as the longer half of the list, and vise versa for the first half of the list.

Below is what was tested by the user input to test the program written in WordPad:

binarysearch1

The above code is a sample of how the code in WordPad is run. After calling “consult” to find the file path to the code, the user is able to run tests. The first, the user asks for an even division of a random list manually entered. The program written in in Word Pad will run through the code and finds the middle number in the given list. The first half of the list is larger than the middle number so the second half of the list contains the middle number. This is why in the print statement, of line two, labels the first part of the list as the numbers coming before the middle number, the middle number is labeled as the center, and second represents the second half of the list. Line three represents the same process but I tested a longer list. In line four, I gave a list that possessed only one number. The struggle I had was trying to get the output to display first and second with zero instead of not showing up at all. The code prints out just the center number because there are no numbers coming before or after the given number. On lines five and six I asked the program if the list possessed a specific number. On line five, the code searched through the list to find that 2 was not part of the list. The output number as a result is false. Line six does the same thing but the output is true because the number one is a part of the list. The code searches through each number in the list by starting at position zero. Finally, lines seven and eight test to see which number of the list is in the middle. By inserting an X instead of a number, the program searches through the code for a number to match the variable.

Sources used in this blog post:

https://wiki.colby.edu/display/LPE/Prolog+Binary+Search

https://wiki.colby.edu/display/~amvartan/Part+3+%28Binary+Search+Prolog%29

http://v.web.umkc.edu/vm63a/441p5p4.htm

Prolog: Programming for Artificial Intelligence by Ivan Bratko

Prolog and Recursion

Unlike languages we have learned previously, such as Java, Prolog uses loops often, but they are not declared in the syntax the same way Java is. Prolog uses the process called recursion in order to allow for a set of instructions to occur multiple times until a specific condition is met. Prolog can not execute a task without the usage of recursion because recursion only appears when a predicate containing the goal refers to itself. There are certain ways recursion can be used in Prolog. The recursive rule definition in Prolog is defined by two rules, one defining the direct predecessor, and the second being the indirect predecessor.

Let’s look at an example of how the predecessor and indirect predecessor can be defined. We can say that “some X is an indirect predecessor of some Z if there is a parentship chain of people between X and Z” (Prolog: Programming for Artificial Intelligence, Ivan Bratko). The program I am using is a family program that does a very good job explaining how recursion works. In order to find the condition that is specifically requested by the user, the program runs through the first line, the second, and so on in order to unify the parent to the predecessor. If the first line (fact) is true, then the program stops calling.

familypic

This image above is created in Word Pad and later called in SWI-Prolog. The relations above explain that the first object (X) is the parent to the second object (Y). Each line declares which person is the parent of the previous object. When ancestor is called we use the “recursive rule for ancestor”. In order to see what ancestor is, the program reads through each line, and not until the line of parent(tom,bob). does the call to ancestor succeed. After that, each line through the call of ancestor is successful because it is referring to a line above that meets the request of the user. We can assume that ancestor refers to a line of the family that falls before the called object.

familypic2

Although I created some errors in testing my program, the outcomes that all read true are the outcomes to be focused on. For the first input, I asked if tom was a parent to bob. By reading through the lines until finding what was called, the first input is true. The next input asked if tom is an ancestor to bob which claimed the statement was true because for bob, the ancestor is tom. On line nine, I asked for who was tom an ancestor to? I replaced the object following tom with Z because that is the letter I used to call the parent and who they are an ancestor to. The output for this was bob, so this proves that the program read through each line until it called itself. Finally, on line eleven, I asked the program if pam was an ancestor to bob. By reading through the program, the output reads true. Because the output is true, this means that for bob, the ancestor is pam, even though she is from a previous relation above. By using the recursive rule of ancestor, the program reads through each line to see if what was called is the ancestor to the previous object (Z) who is either a child to or an ancestor to another object.

I used another example to show how Prolog uses recursion. For this example, I used Prolog to calculate factorials with recursion. I created each number to only hold one solution when writing the code in Word Pad. What this example shows is that when the user calls to find a factorial of six the program will first run through the list of numbers, 0!,1!,2!,3!,4!,  5! and 6!. This means that that the program tries to calculate not (!) each number until reaching six, and then the result will be 0!*1*2*3*4*5*6. This means that each number except for zero, stated in the Word Pad document:

X1 is X – 1,

factorial(X1,Z),

Y is Z*X,!.
is called to be multiplied by the number following it until reaching the number called, which is six. This is an example of recursion because the program will loop through a list of numbers endlessly to be multiplied by the previous solution to reach a factorial of the number called. It is finding the result to itself.

factorial
The code above is what was created in the Word Pad document.

fcatorial2
The results formed in SWI-Prolog are what is shown. What is entered by the user is the call to find the factorial (X) of the number five, six or one. I called random numbers to show different results, but what the program did is run through a number starting at zero for each number called by the user. Until the program finds the number called (itself), it will continuously run through the program.

I felt that trying to figure out what recursion meant for Prolog was somewhat difficult, but by looking at examples online and in the book I use as a source, I was really able to understand how recursion rules work. Recursion is a process that I was not familiar with.

The sources I used for this blog post and examples are:

Prolog: Programming for Artificial Intelligence by Ivan Bratko

and

http://boklm.eu/prolog/page_6.html#622 (this site is what allowed me to find helpful examples I could understand and present)

Prolog Conditionals

Considering the fact that Prolog is a declarative language, the programming syntax for conditional statements is written differently than a language we have previously learned such a Java. Because Prolog is mainly based upon relations, there are no if, then, else statements that define a relation between different objects. Instead of using a basic program that tests whether a number is odd or even, positive or negative, or zero, Prolog can answer a question or a sentence that needs to be written. The process by which Prolog can define if-then rules is through the process backward and forward chaining. Prolog can deal with human reasoning. For example, the book, Prolog: Programming For Artificial Intelligence by Ivan Brakto, used an example with trying to find results of a tennis match. In order to write an if then statement, the input into Word Pad should be one of this example:

beat(tom,jim).

beat(ann,tom).

beat(pat,jim).

The above are facts that are not relations organized in any specific way. In order to define this relation, we need:

class(Player, Category)

To explain this relation, you have requested the usage of three specific categories: a winner (all the players that have won all their matches), a fighter (a player that has won and lost matches), and a sportsman (who has not won any match they have been in). There are now rules for each of the three categories. For winners, we want to say:

X is a winner if X has beaten some Y and X was not beaten anybody.

A rule that a fighter has to possess in the program is this:

X is a fighter if there is some Y such that X beat Y and there is some Z such that Z beat X.

In order to determine the rules for just a sportsman who has not won a single match the rules must combine the rules for the winner and the fighter:

“If X beat somebody and X was beaten by somebody then X is a fighter,

(elseif) otherwise if X beat somebody then X is a winner,

(elseif) otherwise if X got beaten by somebody then X is a sportsman.

There is a piece of code that is formulated in Word Pad file that is uploaded in SWI-Prolog by calling the file name. The code placed into Word Pad shall be:

class( X, fighter) :-

beat( X, _),

beat( _, X), !.

class( X, winner) :-

beat( X,_), !.

class(X, sportsman) : –

beat( _, X).

Notice the “!” which refers to the term NOT, which is a term that can be used in a program such as Java. When this is used we are saying “if not this phrase, then the next is correct.” The facts given at the beginning that are inserted into the WordPad document show that if the problem executes correctly, then Ann and Pat will be winners, Tom will be a fighter, and Jim will be a sportsman.

ifthen2

Once calling the file path on SWI-Prolog, the user will not see the relations by which were created but can ask the program if their input statement is correct. The input will result with an output of true or false from the program. The program calls the file saved on WordPad through “consult(“filename”).”.  There are a couple ways of asking SWI- Prolog who is a winner, fighter, or a sportsman. One way is this:

?- class(tom, C).

C = fighter.

                         (output of program)        false

The user is using class to input parameters, the name of the person (Tom), and C which is allowing the user to input the possibility of C not (!) being equal to fighter, winner, or sportsman. The output the program gives states whether the input is correct or not. In this specific case, tom is not a fighter, so when the user asks the program “is Tom not a fighter?” It answers no because tom is a fighter according to the program. Another input to test the WordPad developed program is:

?- class (tom, sportsman).

                                                            true

This is specifically asking the program if tom is not a sportsman. The program answers yes because Tom is not a sportsman but a fighter. Below are examples I tested to show what the user would input into SWI-Prolog. On line five, I called the file needed to be executed. On line six and seven, I displayed the results of the explained lines above. I continued to test my own inputs and got specific results relating to the phrases I input. On line eight I tested whether Ann is a winner, and the output claimed the statement to be true. On line nine, I asked the program if Jim was a winner and because he is a fighter, the output statement became false. For line ten, I asked the program who was specifically a sportsman, and the output was X equals Jim. X is set equal to Jim because the input replaced Jim with the variable X which asked the program what is the missing factor to the equation was.

ifthen1

The source I used for this blog post was:

Prolog: Programming For Artificial Intelligence by Ivan Brakto

Prolog Variables, Constants, and Arithemetic

The way in which most languages view variables, constants, and arithmetic, is viewed and labeled differently in Prolog than in what we have previously learned. Constants and variables are used to describe relations which are much different than how than how a function shows variables and constants. Consants in Prolog are called atoms. Constants represent specific objects, items, elements, and values. Atoms can be created in three different ways:

  1. strings of letters, numbers, and underscores (_), beginning with lowercase letters. (i.e. sara, x25, miss_Bourlas, sara_smith, y_ _ _y, etc.)
  2. strings of special characters (i.e.  <—> , …, =====>, +, -, <, >, =, &, *, /) – Some of these special characters already have predefined meanings such as ‘:-‘.
  3. Strings of characters enclosed in a pair of single quotes. If we wish an atom to begin with a capital letter and do not want the atom to become a variable (i.e. ‘Suzie’ , ‘North_America’)

Variables are objects that begin with uppercase letters, and can be represented by anything such as a number, a name, an array. Prolog will manipulate variables until they eventually have specific values. When variables are being tested “yes” and “no” are used to see if the values for variables make a solution. Prolog has a systematic way of defining variables. Variables can be recognized as an “anonymous” variable when they appear in a clause one time because the user does not have to create a name for the variable. For example:

hasachild(X) :- parent(X, _).

The property “hasachild” is not dependent on the name of the child variable “X”. This clause says for all X, X has a child if X is a parent of some Y. When a single underscore is used in a clause, this represents that there is a new anonymous variable.

Let’s look at the arithmetic side of Prolog. There are basic predefined operators such as +, -, *, /, div (rounds to a whole number without showing the remainder), and mod (the remainder of integer division). In a simple math problem such as X = 1 + 2, Prolog will have an output of X = 1 + 2. In order to have Prolog activate the addition problem, the special operator “is” is used to force the evaluation of the problem. So to complete an easy math problem one would use:

?- X is 1 + 2

Where the output will be:

X = 3

There is always a tree structure that can define a relation in an arithmetic problem. With the problem above, the tree diagram shows:

                                               +

                                     /                    \

                                 1                           2

There are two examples I will discuss in basic arithmetic. One is finding a common divisor, and a second will be counting the number of items in a list. First to find a common divisor, we denote that X and Y are two positive integers and their greatest common divisor will be D. To solve this we must look at three cases with which this problem must be solved:

  1. If X and Y are equal then D is equal to X.
  2. If X < Y the D is equal to the greatest common divisor of X and the difference Y – X.
  3. If Y < X, then do the same in situation 2 where X and Y are interchanged.

Let’s say that X = 25 and Y = 30, and by following the cases above, D = 5. The math problem is solved through these specific cases:

gcd(X,X,X).

gcd(X,Y,D): –

         X < Y,

        Y1 = Y – X ,

        gcd(X, Y1, D).

gcd(X,Y,D) : –

        Y < X ,

        gcd(Y, X, D).

The second problem I am going to discuss the number of items in a list.

length ( [ ], 0 ) .

length( [ _ | Tail ], N ) :-

               length ( Tail , N1 ),

               N = N1 + 1.

The question the user then asks is:

              length([b,c,d,e],N).

           * N = 1+ (1+(1+(1+0)))

             The answer is N=4

Within this math problem, we see that 0 represents if the list is empty, the length is zero. If the list is not empty, we then see that the length of the list is 1 plus the length of the tail of the list.

The source I used for this blog post was the book, Prolog Programming for Artificial Intelligence: Second Edition by Ivan Brakto

Hello World!

The process of creating the Prolog program for Hello World was a very simple program to create within the SWI-Prolog. In line one the code:

 write(‘Hello world!’). nl.

The source code for this program appears. In order to run this code, I pressed enter after the code to reveal the output. If there were to be an error in the program, the word false instead of true would have appeared showing that the syntax of the program is incorrect. The alterations to make to this program code that would still allow the output to read true is if “write” was written as “writeln.” Writeln simply means “write line.” nl written in the code, that is used but not required, means a new line should be created for the output. By putting a period at the end of the code, this lets the program know that the user has completed the code they wish to input.

blogsecondpost

For more complex programs, in order to run a program, an easy text editor to install is Word Pad, which is typically a program that comes with your computer, if you have a computer other than a Mac. If the feature is not on your computer, a great site to go to http://en.softonic.com/s/free-wordpad to download this text editor. For this program specifically, I installed SWI-Prolog http://www.swi-prolog.org/download/stable which provided files that allowed me to open the SWI-Prolog program, along with libraries of syntax and examples to test and make sure the program is running properly. There are different programs to download that will run code for Prolog but the one I chose was SWI-Prolog.

Typically for longer programs, there is a way to upload a file from Word Pad and use its contents to define relations between certain objects. Although I use settings for Windows, on the installation website there are options for computers such as Mac and Unix. In order to save a Prolog file, the extension has to be .pl. The file can be uploaded through a process found on http://www.swi-prolog.org/FAQ/LoadProgram.html but different systems require different ways to upload files.

My experience so far with this language has been slightly difficult because it is hard to find where to save a Prolog file and be able to access and run it through SWI-Prolog. Simple programs are easy to produce and understand but ones that are more complex require a greater upload and accessing process. I feel that there is a lot to learn of this language and finding what directions mean on websites to know how o upload files can get confusing because I have never learned this before. Getting this program specifically to run was very reasonable. This did not take massive amounts of effort, but I believe future programs will require more effort and success may be partial at first. Previously I did have to change languages, so compared to the first language, I enjoy the success rate and understandably of this language much better.

Learning Prolog

Due to the difficulty of my language, I have switched my self-taught language to Prolog.

The Prolog language came about in the early 1970’s which attempted to use logic as a programming language. The developers of this language were Robert Kowalski, who created the theoretical side of the language, and Maarten van Emden demonstrated the language, and Alain Colmerauer who implemented the language. The program was created because programmers wished to have a programming language that applied logic.

Prolog (programming in logic) is one of the first general purpose logic programming languages that can be . This language is used to express logic as relations, and a query runs over these relations, defined by clauses. Prolog shows the relation between structured objects. This language is useful for “pattern matching, tree-based data structuring and automatic backtracking”(Bratko xi). This program is very flexible and uses some imperative programming when logic is not helpful.

The online references I will be using are http://www.swi-prolog.org/ the website I used to install Prolog. This website has tutorials and documentation of different example programs for Prolog. Another online reference I am using is  http://www.cpp.edu/~jrfisher/www/prolog_tutorial/contents.html . This is a website that links to multiple tutorials for Prolog that allow one to explore the language.

The helpful sources I will be using for this blog are Prolog Programming for Artificial Intelligence: Second Edition by Ivan Brakto. This book has syntax and basic programs and language that Prolog possesses.

The working interpreter is Swi-Prolog that allows one to type small programs with a specific logical output. Logical objects and relations can be originally written in WordPad, and called and interpreted in Swi-Prolog.

 

 

The Opa Language

The Opa programming language appeared in 2011 and was developed by a French company, MLstate. The goal of creating this web developer program was to allow the production of web applications. They wished for the production of the web applications to be easier and more straightforward, as well as being safer. The language was shown at the OWASP convention in 2010 and source codes were later released on GitHub in 2011. The success of this language is attributed to the MIT license applications designed with Opa that allow for the releasing to any open source. The goal of the language was to have a single programming language to code different aspects of an application.

Opa is a compiled programming language that has the ability to limit the complexity of the language for the programmer. Typically, languages in web development require different domains, such as HTML, CSS, JavaScript, and Python. With Opa, the client code, the server code, and the database code are in one single bundle, but still use the datatypes CSS, HTML and JavaScript. What is super accommodating about this language is that the HTML files, the JavaScript source, image files, and CSS files, are put together by one single compiler. This in result means that there is only one single file to export, creating a safely built application.

Opa is a programming language that generates a client-side JavaScript using Node.js on the server-side. The Opa compiler mechanically skips XHTML values, a stricter and similar language to HTML. This means that you will not have to call values used within the XHTML language and the program will figure it out for you if XHTML is stored inside the program.

Opa allows for mistakes to be made without having to rebuild the entire application although everything is executed together. Opa has a debugging system called “opa-debug” which searches into a directory and replaces the original file embedded in the application by the programmer, with the correct copied file from the directory.

In order to complete a reasonably sized program I will be using Eclipse as my text editor. Eclipse will be where my code is entered and will be compiled through Opa’s compiler through a process called “typechecking”. One special feature Opa has is that the program will tell you through the process of “slicing”, which parts of the designed program run on the server, database, and on the client. The client-side code is then translated from Opa to JavaScript. The outcome of the program will then be displayed in a browser with the URL http://localhost:8080.

In order to receive assistance in the learning process of Opa I will be referring to two books revealing the basics and design of the coding. One is called Opa Up and Running by Henri Binsztok, Adam Koprowski, and Ida Swarczewskaja. The second book is Opa Application Development by Li Wenbo.

The online source I shall use in order to find core language and helpful tips is GitHub with the link https://github.com/MLstate/opalang/wiki/The-core-language .

Sources Used for Information:

http://www.javaworld.com/article/2078521/mobile-java/programming-opa–web-development–reimagined.html

https://en.wikipedia.org/wiki/Opa_(programming_language)

http://www.infoworld.com/article/2620269/web-development/introducing-opa–a-web-dev-language-to-rule-them-all.html

http://developers.slashdot.org/story/11/08/27/2115210/Announcing-Opa-Making-Web-Programming-Transparent

http://us.wow.com/wiki/Opa_(programming_language)