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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started