Question: Write a Prolog source file take.pro as follows. Be sure to follow the Coding Standards. Your file should define the predicate take/3. Predicate take should

Write a Prolog source file take.pro as follows. Be sure to follow the Coding Standards.

Your file should define the predicate take/3.

Predicate take should take arguments as follows: take(+n, +x, ?e).

The idea is that n is a nonnegative integer, x is a list, and e is a list consisting of the first n items in x, or all of x, if x has fewer than nitems.

If n is a nonnegative integer, and x and e are both lists, then take succeeds if e is the correct list.

If n is a nonnegative integer, x is a list and e is an unbound variable, then take succeeeds, with e set to the proper list.

Your code does not need to do any type checking or other error checking.

Here is a sample Gprolog session using take.

[Interactive Prolog]

| ?- [take]. compiling /home/ggc/PROLOG/take.pro for byte code... /home/ggc/PROLOG/take.pro compiled, 14 lines read - 570 bytes written, 11 ms yes | ?- take(2,[0,1,2],[0,1]). yes | ?- take(6,[7,9,8,4],[7,9,8,4]). yes | ?- take(5,[0,1,2],[0,1]). no | ?- take(2,"abc","ab"). yes | ?- take(0,[1,2],[]). yes | ?- take(4,[100,3,200,4,600,5,900,1000000],E). E = [100,3,200,4] yes 

Your file may define any other symbols you wish.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!