Skip to content

Instantly share code, notes, and snippets.

@jarble
Last active August 21, 2021 21:17
Show Gist options
  • Save jarble/ab19604d2810aa27810f5142c0637b4e to your computer and use it in GitHub Desktop.
Save jarble/ab19604d2810aa27810f5142c0637b4e to your computer and use it in GitHub Desktop.
An example of duplicate code detection in Prolog
:- initialization(main).
:- set_prolog_flag(double_quotes, chars).
main :-
duplicate_code(
(G<A;A>B+1;C>D+1),
Output),
writeln(Output).
%find a duplicated term within a term
duplicate_code(A,Duplicate) :-
sub_term(Duplicate,A),
nonvar(Duplicate),
sub_term(B1,A),
nonvar(B1),
Duplicate \== B1,
subsumes_term(Duplicate,B1),
subsumes_term(B1,Duplicate).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment