1

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?

false
  • 10,264
  • 13
  • 101
  • 209
Cole Dapprich
  • 33
  • 1
  • 7

2 Answers2

1

Found a built-in sublist function that does exactly what I need:

sublist([i, m], [m, i, m]) ==> `true`
peterh
  • 11,875
  • 18
  • 85
  • 108
Cole Dapprich
  • 33
  • 1
  • 7
1

Consider to use grammars (). 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.

Community
  • 1
  • 1
false
  • 10,264
  • 13
  • 101
  • 209