In my Prolog program I have a predicate reg/1
which says if something is a regular expression. I'd like to make the program recognize sequences of regular expressions as a regular expression. So, if reg(a_1)
, reg(a_2)
, ..., reg(a_n)
are all regular expressions, Prolog should answer yes/true to the query reg(a_1, a_2, ..., a_n)
.
But I don't know how to do it.
What I have done is the following:
reg([H|T]) :- reg(H), reg(T).
reg([X]) :- reg(X).
If, for example, reg(a)
, reg(b)
, reg(c)
are all in the knowledge base, then Prolog answers yes/true to the query reg([a, b])
or reg([b, a, c])
, but I can't ask it something like reg(a, b)
or reg(b, a, c)
, i.e., I can't get rid of the square brackets.