I am trying to create a custom enumeration via a series of facts.
greater(X,Y) :- less (Y,X). less(a,b). less(b,c). less(c,d).
This works fine, however there is significant repetition.
I'm trying to cut that down. Is there a way to use an array for a simple linear series of facts via a transformation?
transform([a,b,c,d]) resulting in the same less definitions.
I have already created a "less" definition that uses an array and the nextto/member function to test, however I cannot add exceptions or equivalent cases like I could with individual declarations. Hence my interest in shortcutting the simple case definition, and then the desire to supplement it with more definitions.
This reminds me of where defmacro in lisp is useful.
Thanks.
Edit:
I was able to generate one series using assert. It successfully defines everything, but returns an error. I get the impression this isn't the correct method.
set_less([]). set_less([X,Y|L]):- assert( myless(X,Y) ) , set_less([Y|L]). :- set_less([a,b,c,d]). Output: Goal (directive) failed: user:set_less([a, b, c, d]) ?- listing. :- dynamic myless/2. myless(a, b). myless(b, c). myless(c, d).
Second Edit:
mylist([a,b,c,d]). set_less([]). set_less([_]). ----- Key! set_less([X,Y|L]):- assert( myless(X,Y) ) , set_less([Y|L]). :- set_less([a,b,c,d]).
That does work! Is this a good way to define custom enumerations? I see it works now, thanks!