Reputation: 93
I am trying to write a predicate in GNU Prolog that tests if a roman numeral, stored as a list of characters, is well formed. Namely, if the list contains [i, c], [i, m], or [x, m], it is invalid. For example, if I passed in [m, i, m], the output would be no
.
How would I go about doing this? I am aware of the member/2 function; is there a way to use that to test if a list contains a sublist?
Upvotes: 2
Views: 197
Reputation: 93
Found a built-in sublist function that does exactly what I need:
sublist([i, m], [m, i, m]) ==> `true`
Upvotes: 2
Reputation: 10102
Consider to use grammars (dcg). And use
:- set_prolog_flag(double_quotes, chars).
which permits you to write "mcm"
in place of [m,c,m]
. See this answer for more.
Upvotes: 1