Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Your problem (superficially) is that member/2 get called with an uninstantiated variable, and then 'builds' the partial list that you see in the output</p> <pre><code>[trace] ?- setify([1],X). Call: (6) setify([1], _G340) ? creep Call: (7) appendHlp(_G340, _G416, 1) ? creep ^ Call: (8) not(member(1, _G340)) ? creep ^ Fail: (8) not(user:member(1, _G340)) ? creep Redo: (7) appendHlp(_G340, _G416, 1) ? creep Call: (8) lists:member(1, _G340) ? creep Exit: (8) lists:member(1, [1|_G409]) ? creep Call: (8) _G418=[1|_G409] ? creep Exit: (8) [1|_G409]=[1|_G409] ? creep Exit: (7) appendHlp([1|_G409], [1|_G409], 1) ? creep Call: (7) setify([], [1|_G409]) ? creep Exit: (7) setify([], [1|_G409]) ? creep Exit: (6) setify([1], [1|_G409]) ? creep X = [1|_G409] . </code></pre> <p>It's not easy to correct, because you use a <strong>very</strong> convoluted way to do a <strong>very</strong> simple task. If you replace, for instance, member with memberchk, or <code>member(Addme,ListOrg)</code> with <code>[Addme]=ListOrg</code>, your program will fail.</p> <p>I would advise to take some programming habit accepted by Prolog community. For instance, attempt to place <em>input</em> parameters <em>before</em> output. It's not always possible, because Prolog is <em>relational</em>, but will help to write better code.</p> <p>Of course, sort/2 would produce the output efficiently and without hassle.</p> <p><em>edit</em> the solution can be quite compact, in basic Prolog:</p> <pre><code>setify([E|R], U) :- memberchk(E, R), !, setify(R, U). setify([E|R], [E|U]) :- setify(R, U). setify([], []). 3 ?- setify([1,1,1,2,1,1],L). L = [2, 1]. </code></pre>
 

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