4 ms·
Show HN: An encoding of the UK's self-isolation rules in Prolog
- deleted 6y ago[deleted]
- tyingq 6y agoHah! I was expecting a sort of Brexit joke in Prolog, instead it's something useful :)
- GuB-42 6y agoI expected some kind of joke about really complex rules requiring an expert system to get right. 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...
- scrollaway 6y agoSame in Belgium, where over winter the rules about whether you could see someone or not took into account your age, their age, whether you're indoors or outdoors, how many people you and they have seen that week, whether you are single, whether it's Christmas Eve, what time it is and whether you need assisted care. Oh, and the rules are different if you want to use their bathroom. I'm not making any of this up.
- teruakohatu 6y agoIf you want to read the code: "," is AND and ";" is OR.
- crabmusket 6y agoThank you. I love seeing what different languages choose as the meaning of their primary tokens. For example, Smalltalk uses whitespace to send messages, whereas Haskell uses whitespace to apply functions to arguments.
- alisonkisk 6y agoHaskell doesn't use whitespat for function application. Haskell uses whitespace for tokenization (like most languages), and uses nothing for function application.
- simplify 6y agoAlso, \+ is NOT.
- ilovepitchdecks 6y agoThis Covid joke is getting old.
- Angostura 6y agoA self-referential comment?
- ilovepitchdecks 6y agoCan you elaborate?
- 1_player 6y agoYour own "this Covid joke is getting old" refers to itself. Yes, that comment of yours is getting old.
- YeGoblynQueenne 6y agoNice, but this: 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 https://arxiv.org/abs/0911.2899 Really, really good source on good Prolog style that paper (and where I base my comments above).
- Hbruz0 6y agoI really love Prolog ! That is an awesome project !
- gsnedders 6y agoPedantic 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.
- gandalfgeek 6y agoNot related to the code itself, but this is the most dystopian thing I've seen in a while. "Has ~w receieved a negative result through the Test to Release scheme?" We're all captive and need a test to be "released"?
- heraclius 6y agoThe whole thing may well be dystopian. 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!
- RGamma 6y agoThis is the most dystopian in a while? Geez I wish I had your peace of mind.
- p1necone 6y agoYes, because there's a pandemic. Stop being a selfish twit.
- jakeogh 6y agoThis fear response is making it worth more. Suppose the pandemic never ends? The engineering only gets easier from here.
- X6S1x6Okd1st 6y ago<3 that shell.nix is included
- Tade0 6y ago> I haven't written any Prolog since university. Same here. Anyone here who uses it commercially willing to share their story?
- jimi_d 6y agoI was expecting some sort of parody of the rules but it's actually quite a nice project :)
- juloo 6y agoI was expecting should_isolate(_). meaning always "yes", but it's actually encoding rules.