0
votes

There are the following variables:

colour(blue).
colour(red).
colour(green).

size(small).
size(medium).
size(large).

price(10).
price(25).
price(40).

I want to make a list that will return every possible compination. Something like:

list=([colour(X),size(X),price(X)]).

Is it possible?

1

1 Answers

1
votes

I'm not sure that I understood correctly but you could try:

find_comb(L):- findall((X,Y,Z), (colour(X), size(Y), price(Z)) , L).

The above uses findall/3 predicate to collect all possible combinations and store it in L.

Example:

    ?- find_comb(L).
    L = [ (blue, small, 10), (blue, small, 25), (blue, small, 40), (blue, 
    medium, 10), (blue, medium, 25), (blue, medium, 40), (blue, large, 10), 
    (blue, ..., ...), (..., ...)|...].

Based to your comment, to see full answer without '...' you could add:

?- set_prolog_flag(answer_write_options,
                   [ quoted(true),
                     portray(true),
                     spacing(next_argument)
                   ]).