5 SPL Syntax Reference
| (require spindle/lang) | package: spindle |
SPL (Spindle LISP) is an S-expression syntax for Spindle theories, designed for Racket users who prefer parenthesized notation.
5.1 Facts
Use given to declare facts:
(given bird) (given penguin)
5.2 Rules
5.2.1 Strict Rules (always)
Rules that always apply, cannot be defeated:
(always r1 human mortal) (always r2 (a b) c) ; Multiple premises
5.2.2 Defeasible Rules (normally)
Rules that typically apply but can be overridden:
(normally r1 bird flies) (normally r2 student busy)
5.2.3 Defeaters (except)
Rules that block conclusions without asserting the opposite:
(except d1 broken-wing (not flies))
5.3 Negation
Use not for negated literals:
(not flies) (normally r1 penguin (not flies))
5.4 Superiority
Use prefer to declare which rules win conflicts:
(prefer r2 r1) ; r2 defeats r1
5.5 Multiple Premises
Wrap multiple premises in a list:
(normally r1 (fever cough) has-flu) (always r2 (a b c) conclusion)
5.6 Comments
Use semicolons for comments:
; This is a comment (given bird) ; Inline comment
5.7 Modal Operators
SPL supports deontic modal operators:
(must pay-taxes) ; Obligation (may access-resource) ; Permission (forbidden enter-restricted) ; Prohibition
In rules:
(normally r1 employee (must attend-meetings)) (normally r2 member (may access-library))
5.8 Using #lang spindle
Create .spl files with the #lang spindle directive:
"theory.spl"
#lang spindle (given bird) (given penguin) (normally r1 bird flies) (normally r2 penguin (not flies)) (prefer r2 r1)
Then use in Racket:
(require "theory.spl") (spindle-conclusions)
5.9 Programmatic Use
(require spindle/lang) (define conclusions (reason-spl-string "(given bird)\n (normally r1 bird flies)")) (reason-spl-file "theory.spl")
5.10 Complete Example
#lang spindle ; Medical diagnosis example ; Patient symptoms (given has-fever) (given has-cough) (given has-rash) ; Diagnostic rules (normally r1 (has-fever has-cough) has-flu) (normally r2 (has-fever has-rash) has-measles) (normally r3 has-measles (not has-flu)) ; Measles is more specific diagnosis (prefer r3 r1)
5.11 SPL vs DFL Comparison
Concept |
| DFL |
| SPL |
Fact |
| >> bird |
| (given bird) |
Strict rule |
| r1: a -> b |
| (always r1 a b) |
Defeasible |
| r1: a => b |
| (normally r1 a b) |
Defeater |
| d1: a ~> b |
| (except d1 a b) |
Negation |
| ¬a |
| (not a) |
Superiority |
| r2 > r1 |
| (prefer r2 r1) |