I am trying to create a custom enumeration using a series of facts.
greater (X, Y): - less (Y, X).
less (a, b).
less (b, c).
less (c, d).
This works great, but there is significant repetition.
I am trying to do this. Is there a way to use an array for a simple linear series of facts through conversion?
transform ([a, b, c, d])
resulting in the same less definitions.
I have already created a less definition that uses the array and the nextto / member function for testing, however I cannot add exceptions or equivalent cases, as I could, with separate declarations. Hence my interest in reducing the simple definition of a case, and then in the desire to supplement it with additional definitions.
, defmacro lisp.
.
Edit:
, assert. , . , .
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).
:
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]).
! ? , , !