<blockquote>
<p>which one follows the best practices of Prolog?</p>
</blockquote>
<p>The first one.</p>
<p>Using =/2 is not common. I am not saying to avoid it but most production code tends to refactor them out.</p>
<p>For more info see: <a href="https://arxiv.org/pdf/0911.2899.pdf" rel="nofollow noreferrer">Coding Guidelines for Prolog</a></p>
<hr />
<p>If you are using SWI-Prolog with <a href="https://www.swi-prolog.org/pldoc/man?section=ssu" rel="nofollow noreferrer">Single Side Unification</a>, then using =/2 is not only common but in some cases necessary.</p>
<p>See: <a href="https://swi-prolog.discourse.group/t/example-of-refactoring-code-to-ssu/4713" rel="nofollow noreferrer">Example of refactoring code to SSU</a></p>
<hr />
<p>If you are using <a href="https://www.swi-prolog.org/pldoc/man?predicate=listing/1" rel="nofollow noreferrer">listing/1</a> to look at DCG code then you will see <a href="https://www.swi-prolog.org/pldoc/doc_for?object=(%3D)/2" rel="nofollow noreferrer">=/2</a> used quite often. This is because the compiler is playing it safe and not refactoring the code to avoid introducing a bug.</p>
Best Practices for Prolog predicates definition
<p>I have defined the predicate duplicate_elements/2 whose definition is as follows:</p>
<p>duplicate_elements(L1, L2): L1 = [a,b], L2 = [a,a,b,b]</p>
<p>I would like to know, between the two alternatives 1 and 2, which one follows the best practices of Prolog:</p>
<pre><code>duplicate_elements_1([],[]).
duplicate_elements_1([P | R],[P,P | T]) :- 
    duplicate_elements_1(R , T).
</code></pre>
<pre><code>duplicate_elements_2([],[]).
duplicate_elements_2([P | R],[H1,H2 | T]) :- 
    H1 = P,
    H2 = P,
    duplicate_elements_2(R , T).

</code></pre>
<p>Thanks</p>