Here is a predicate in Prolog: fl (a, [], []) fl (A, [A|T], R):- fl (A, T, R). f
ID: 3581773 • Letter: H
Question
Here is a predicate in Prolog: fl (a, [], []) fl (A, [A|T], R):- fl (A, T, R). fl (A, [H|T], R) fl (A, T, R1), R = [H|Rl]. What is the output of the following: fl (x, [a, b, c], R). R = [a, b, c] What is the output of the following: fl (x, [[x, y], x, y], R). R = [[x, y], y] Here is a function in Prolog: f2 (0, [H|T], H). (N, [], 0). f2 (N, [H|T], R) Nl is N - 1, f2 (NI, T, R). What is the output of the following: f2 (3, [a, b, c], R). R = 0 What is the output of the following: f2 (2, [a, b, c], R). R = c Here is a function in Prolog: f3 ([], 0). f3 ([H|T], N):- number (H), f3 (T, N1), N is N1 + 1. f3 ([H|T], N) beta (T, N). What is the output of the following: f2 ((a, 2, c], R). R = 1 What is the output of the following: f2 ((1, [2, 3], 4, [5, 6]], R). R = 2Explanation / Answer
a) This predicate replaces the letter.
Output for the first question f1(x, [a,b,c], R), R=[a,b,c] is
| ?- f1(x,[a,b,c],R)
Yes
Output for the second question f1(x,[[x,y],x,y],R), R=[[x,y],y] is
| ?- f1(x,[[x,y],x,y],R)
No
c) This predicate detemines the length of a list.
Output for f2([a,2,c], R), R=1 is
f2([a,2,c], R) where the list consits of 3 elements but R is 1. Hence the answer is No.
| ?- f2([a,2,c], R)
No
Output for f2([1, [2,3], 4, [5,6]], R), R=2 is
f2([1, [2,3], 4, [5,6]], R) where the list written here consists of 4 elements but R is 2. Hence the answer is No.
| ?- f2([1, [2,3], 4, [5,6]], R),
No