Write a predicate reverse/3
using DCG grammar rules. This predicate should be true is and only if the content of the difference list formed by the last two arguments is the reverse of the first argument. The mode of the predicate may be (+,-,-)
.
?- reverse([1,2,3],X,[]).
X = [3, 2, 1].
?- reverse([1,2,3],X,[a]).
X = [3, 2, 1, a].
?- reverse([1,2,3],X,Y).
X = [3, 2, 1|Y].