I've a problem. I have 5 constants.
C(1).
C(2).
C(3).
C(4).
C(5).
And I've a predicate named "check" that receives two arguments.
Example:
check( [C(1), C(3), C(4), _, C(5)], ListFinal).
And now it should give me
ListFinal = [C(1), C(3), C(4), C(2), C(5)].
How do I do this? How to check for that black space to put there, the constant I haven't used? It is possible to change the implementation of the constants.
Some tests:
Here's a DCG approach:
You could try
You might also look at
findall/3
.You should note however, that your 'constants' aren't constants in prolog. The way you've written them they are are facts. And the ones you've listed aren't syntactically valid Prolog: The functor of a term must be either a bareword atom like
c(3).
or an atom enclosed in single quotes like'C'(3).
(though why anybody would voluntarily choose to do something like that is beyond me.)once corrected the syntax, check each argument (easy to do with maplist/3)
usage example