Note that there are some explanatory texts on larger screens.

plurals
  1. POProlog shortcut to creating a custom enumeration
    primarykey
    data
    text
    <p>I am trying to create a custom enumeration via a series of facts.</p> <pre> greater(X,Y) :- less (Y,X). less(a,b). less(b,c). less(c,d). </pre> <p>This works fine, however there is significant repetition.</p> <p>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?</p> <pre> transform([a,b,c,d]) resulting in the same less definitions. </pre> <p>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.</p> <p>This reminds me of where defmacro in lisp is useful.</p> <p>Thanks.</p> <p><strong>Edit:</strong></p> <p>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.</p> <pre> 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). </pre> <p><strong>Second Edit:</strong></p> <pre> 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]). </pre> <p>That does work! Is this a good way to define custom enumerations? I see it works now, thanks!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload