4

Is there a way to turn this:

genre(blues).
gere(hiphop).
genre(rock).

Into something like this:

genre(blues;hiphop;rock).

*I know this does not work, but does something similar to this exist.

false
  • 10,264
  • 13
  • 101
  • 209
Mr. Polywhirl
  • 42,981
  • 12
  • 84
  • 132

3 Answers3

2

You cannot consolidate facts, but you can turn them into a simple rule, like this:

genre(X) :- member(X, [blues, hiphop, rock]).

member/2 is a built-in list predicate in SWI to test list membership.

Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523
1

This lets you apply a predicate across all of the elements of a list, and will succeed only if all applications succeed.

test_list( _, [] ).
test_list( F, [H|T] ) :- P =.. [F,H], P, test_list( F, T ).
Scott Hunter
  • 48,888
  • 12
  • 60
  • 101
0

You could use this syntax

genre(X) :- X=blues ; X=hiphop ; X=rock.

but personally I advice the member/2 way...

CapelliC
  • 59,646
  • 5
  • 47
  • 90