Question: /* Problem 2: The following are two basic predicates for list manipulation: my_first/2 and my_last/2. We may refer to a predicate by writings it as

/* Problem 2:

The following are two basic predicates for list manipulation: my_first/2 and my_last/2. We may refer to a predicate by writings it as name/arity; hence, my_first/2 means a predicate named my_first with two arguments.

my_first(X,Y) succeeds if X is the first element of list Y. my_last(X,Y) succeeds if X is the last element of list Y.

Write definitions for my_first and my_last. */

/* Problem 2 Test: */ %:- my_first(a, [a]). % SUCCEED %:- my_first(3, [3, 2, 1]). % SUCCEED %:- my_first(3, [4, 3, 2, 1]) -> fail ; true. % FAIL %:- my_last(a, [a]). % SUCCEED %:- my_last(1, [3, 2, 1]). % SUCCEED %:- my_last(1, [3, 2, 1, 0]) -> fail ; true. % FAIL

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!