Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications 33rd International Conference Dexa 2022 Vienna Austria August 22 24 2022 Proceedings Part 2 Lncs 13427

Authors: Christine Strauss ,Alfredo Cuzzocrea ,Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil

1st Edition

3031124251, 978-3031124259

More Books

Students also viewed these Databases questions