Without some sample data and expected/desired results, it's a bit hard to tell what you need. However...Examining the state of the argument in your predicate might give you what you're looking for.
For example, given this data:
foo( albania , 1 ) .
foo( albania , 2 ) .
foo( albania , 3 ) .
foo( albania , 4 ) .
foo( albania , 5 ) .
foo( albania , 6 ) .
foo( iceland , 4 ) .
foo( iceland , 5 ) .
foo( iceland , 6 ) .
foo( iceland , 7 ) .
foo( iceland , 8 ) .
foo( iceland , 9 ) .
foo( france , 7 ) .
foo( france , 8 ) .
foo( france , 9 ) .
foo( france , 10 ) .
foo( france , 11 ) .
foo( france , 12 ) .
Your initial cut at things shown in your question
predicate(Country, X):-
setof(Length, foo(Country,Length), X).
returns these multiple results when invoked with Country
being an unbound variable:
?- predicate(Country,X).
Country = albania , X = [1, 2, 3, 4, 5, 6] ;
Country = france , X = [7, 8, 9, 10, 11, 12] ;
Country = iceland , X = [4, 5, 6, 7, 8, 9] .
And this single result if invoked with Country
being bound to a valid country, iceland
in this case:
?- predicate(iceland,X).
X = [4, 5, 6, 7, 8, 9].
If you do something like this, however,
predicate( C , Xs ) :- var(C) , setof( X , C^foo(C,X) , Xs ) .
predicate( C , Xs ) :- nonvar(C) , setof( X , foo(C,X) , Xs ) .
You'll get this one solution when the argument is unbound:
?- try_this(C,Xs).
Xs = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] ;
false.
You'll notice that C
remains unbound.
And you'll get this this one result when the argument is bound:
?- try_this(iceland,Xs).
Xs = [4, 5, 6, 7, 8, 9].