Nice, but this:<p><pre><code> should_isolate(Person) :- has_symptoms(Person);
tested_positive(Person);
(
lives_with_others(Person),
format(atom(LivingWithPeople), 'anyone living with ~w', Person),
(
has_symptoms(LivingWithPeople);
tested_positive(LivingWithPeople)
)
);
(
in_bubble(Person),
format(atom(BubblePeople), 'anyone in ~w\'s bubble', 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'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's different to follow the program flow. More importantly, it's hard to see at a glance whether some "cases" 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 ->/2 which amounts to a "soft cut" after the first <condition>:<p><pre><code> ( <if-condition>
-> <then-consequence>
; <else-alternative>
)
</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 "cases" of your program's logic.<p>Also, bad idea to interleave messages to user with "business logic" like you do, e.g. in:<p><pre><code> lives_with_others(Person),
format(atom(LivingWithPeople), 'anyone living with ~w', Person),
</code></pre>
It's possible with a bit of elbow grease to completely separate the I/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://arxiv.org/abs/0911.2899" rel="nofollow">https://arxiv.org/abs/0911.2899</a><p>Really, really good source on good Prolog style that paper (and where I base my comments above).