Show HN: An encoding of the UK's self-isolation rules in Prolog
Nice, but this:<p><pre><code>  should_isolate(Person) :- has_symptoms(Person);
                            tested_positive(Person);
                            (
                                lives_with_others(Person),
                                format(atom(LivingWithPeople), &#x27;anyone living with ~w&#x27;, Person),
                                (
                                    has_symptoms(LivingWithPeople);
                                    tested_positive(LivingWithPeople)
                                )
                            );
                            (
                                in_bubble(Person),
                                format(atom(BubblePeople), &#x27;anyone in ~w\&#x27;s bubble&#x27;, Person),
                                (
                                    (
                                        has_symptoms(BubblePeople),
                                        contact_with_symptomatic_bubble_member(Person)
                                    );
                                    (
                                        tested_positive(BubblePeople),
                                        contact_with_positive_bubble_member(Person)
                                    )
                                )
                            );
                            contacted_by_test_and_trace(Person);
                            (
                                arrived_from_abroad_recently(Person),
                                \+ has_negative_test_to_release_result(Person)
                            ).

</code></pre>
Is absolutely awful Prolog style :)<p>First of all it&#x27;s hard to read, not least because you have your semocilons (semicola?) formatted inconsistently: some are at the end of a line, others at the start, so it&#x27;s different to follow the program flow. More importantly, it&#x27;s hard to see at a glance whether some &quot;cases&quot; are meant to backtrack on failure or not. Normally, if you wanted to write a Big Hairy, Horrible Case Statement in Prolog then you should at least use the control flow with -&gt;&#x2F;2 which amounts to a &quot;soft cut&quot; after the first &lt;condition&gt;:<p><pre><code>  (   &lt;if-condition&gt;
  -&gt;  &lt;then-consequence&gt;
  ;   &lt;else-alternative&gt;
  )
</code></pre>
But the recommended thing to make your code easier to read (_and debug_) and less like they do in Java is to use separate clauses to handle different &quot;cases&quot; of your program&#x27;s logic.<p>Also, bad idea to interleave messages to user with &quot;business logic&quot; like you do, e.g. in:<p><pre><code>  lives_with_others(Person),
  format(atom(LivingWithPeople), &#x27;anyone living with ~w&#x27;, Person),
</code></pre>
It&#x27;s possible with a bit of elbow grease to completely separate the I&#x2F;O of communication with the user from the rules-based logic of your program.<p>There are actually coding guidelines for Prolog! Here:<p><a href="https:&#x2F;&#x2F;arxiv.org&#x2F;abs&#x2F;0911.2899" rel="nofollow">https:&#x2F;&#x2F;arxiv.org&#x2F;abs&#x2F;0911.2899</a><p>Really, really good source on good Prolog style that paper (and where I base my comments above).