Is there a way to separate a list in Prolog like this: [1,2,3,4|5]
?
I can write a predicate which separates a head from a tail:
predicate([Head|Tail]).
And I would like to know if I can write something like this:
predicate([Init|Last]).
Init and Last are used in Haskell to separate the last element from its list. Thank you in advance!
0
votes
2 Answers
0
votes
You can use last/2
to yield the last element of a list.
?- A = [1,2,3,4,5], last(A, B).
A = [1, 2, 3, 4, 5],
B = 5.
Difference List
. – Guy Coder