1

I am writing a program for an artistic purpose in Prolog with heavy reliance on a large set of CHR rules. I would like to be able to run many times, but produce a different output each time. The easiest way to do this would be to non-deterministically reorder the constraints each time.

For instance, for the form of a poem, I may want an ABAB or ABAC form. I would then like to write:

stanza <=> verse(A,0), verse(B,1), verse(A,2), verse(B,3)
stanza <=> verse(A,0), verse(B,1), verse(A,2), verse(C,3)

I'd like for the first rule to sometimes fire when stanza is presented, and for the second rule to sometimes fire. How could I accomplish that with CHR?

lightning
  • 389
  • 1
  • 9
  • You can [randomly shuffle a list of numbers](https://stackoverflow.com/questions/27431281/shuffling-a-list-in-prolog) to decide the order. Then, you might need to add another constraint to make the rules fire in that order. – Anderson Green Dec 25 '19 at 20:58
  • @AndersonGreen my understanding was that constraints always fire in their order of definition - how would I redefine them at runtime to run in a different order? – lightning Dec 30 '19 at 18:27

0 Answers0