Show HN: An encoding of the UK's self-isolation rules in Prolog
github.com
github.com
Haskell uses whitespace for tokenization (like most languages), and uses nothing for function application.
Same here. Anyone here who uses it commercially willing to share their story?
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)
).
Is absolutely awful Prolog style :)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>:
( <if-condition>
-> <then-consequence>
; <else-alternative>
)
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.Also, bad idea to interleave messages to user with "business logic" like you do, e.g. in:
lives_with_others(Person),
format(atom(LivingWithPeople), 'anyone living with ~w', Person),
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.There are actually coding guidelines for Prolog! Here:
https://arxiv.org/abs/0911.2899
Really, really good source on good Prolog style that paper (and where I base my comments above).
should_isolate(_).
meaning always "yes", but it's actually encoding rules.I am currently in France, in a kind-of-lockdown. Meaning we can go out in a 10km radius, or 30km, or within your department borders for some activities, but only during the day, with some exceptions. Generally, you need to write a paper where you write your reason for going out, but not during the day if you can show a proof of where you live. And I am not getting into which businesses are allowed to open...
Oh, and the rules are different if you want to use their bathroom.
I'm not making any of this up.
"Has ~w receieved a negative result through the Test to Release scheme?"
We're all captive and need a test to be "released"?
That said, you don’t seem to have looked up what test to release actually is. It’s a scheme for travellers to get out of quarantine early. So no, we aren’t ‘all’ captive to ‘test to release’—we (inhabitants of the UK) are captive to many other regulations though!