Closed Jean-Luc-Picard-2021 closed 3 weeks ago
You could do distinct/1 something like...
distinct(Goal) :-
distinct(Goal, Goal).
:- meta_predicate(distinct(0)).
distinct(Witness, Goal) :-
term_variables(Witness, Vars),
Witness1 =.. [v|Vars],
setup_call_cleanup(
true,
(
Goal,
\+ clause('$distinct'(Witness1, Goal), _),
assertz('$distinct'(Witness1, Goal))
),
retractall('$distinct'(Witness1, _))
),
true.
:- meta_predicate(distinct(0,0)).
I guess it will pass this test case, right?
/* SWI-Prolog, eagerness */
?- distinct(repeat), !.
true.
But it wont pass this test case, right?
/* SWI-Prolog, non-variant enumerating */
d(f(A,A)).
d(f(a,a)).
d(f(B,B)).
?- distinct(d(X)).
X = f(_70321, _70321);
X = f(a, a);
fail.
And this test case will also fail, right?
/* SWI-Prolog, reentrant */
?- distinct((distinct(X=1);distinct(X=1))).
X = 1 ;
false.
Maybe for the future.
I see that Trealla Prolog has a few bifs such as
call_nth/2
,limit/2
andoffset/2
. These bifs are usually explained as inspired by the correspondingSQL database querying language equivalents. But what about a
distinct/1
meta predicate? The predicate is somehow missing:On the other hand in SWI-Prolog I get: