TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Show HN: An encoding of the UK's self-isolation rules in Prolog

108 pointsby jamespwilliamsabout 4 years ago

10 comments

gsneddersabout 4 years ago
Pedantic comment: this encodes the rules from NHS England's website, which are presumably based on the English legislation. Each of the devolved legislatures have their own set of legislation, so this probably doesn't generalise to the entire UK.
teruakohatuabout 4 years ago
If you want to read the code: "," is AND and ";" is OR.
评论 #26774201 未加载
评论 #26774764 未加载
Tade0about 4 years ago
&gt; I haven&#x27;t written any Prolog since university.<p>Same here. Anyone here who uses it commercially willing to share their story?
YeGoblynQueenneabout 4 years ago
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).
评论 #26789983 未加载
X6S1x6Okd1stabout 4 years ago
&lt;3 that shell.nix is included
julooabout 4 years ago
I was expecting<p><pre><code> should_isolate(_). </code></pre> meaning always &quot;yes&quot;, but it&#x27;s actually encoding rules.
jimi_dabout 4 years ago
I was expecting some sort of parody of the rules but it&#x27;s actually quite a nice project :)
tyingqabout 4 years ago
Hah! I was expecting a sort of Brexit joke in Prolog, instead it&#x27;s something useful :)
评论 #26774374 未加载
Hbruz0about 4 years ago
I really love Prolog ! That is an awesome project !
gandalfgeekabout 4 years ago
Not related to the code itself, but this is the most dystopian thing I&#x27;ve seen in a while.<p>&quot;Has ~w receieved a negative result through the Test to Release scheme?&quot;<p>We&#x27;re all captive and need a test to be &quot;released&quot;?
评论 #26774628 未加载
评论 #26774643 未加载
评论 #26775463 未加载