Last active
August 21, 2021 21:17
-
-
Save jarble/ab19604d2810aa27810f5142c0637b4e to your computer and use it in GitHub Desktop.
An example of duplicate code detection in Prolog
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:- 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