-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjsrules.lisp
55 lines (46 loc) · 1.81 KB
/
jsrules.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
;;; -*- Mode: LISP; -*-
;;;; Basic rules for JSAINT.
;(in-package :COMMON-LISP-USER)
;;; Expand pointers
(rule ((:IN (AND-SUBGOALS ?parent ?children) :VAR ?def))
(dolist (child ?children)
(rlet ((?child (:EVAL child)))
(rassert! (PARENT-OF ?child ?parent :AND)
(:DEF-OF-AND ?def))
(rule ((:IN (failed ?child) :VAR ?delinquent))
(rassert! (failed ?parent)
(:AND-FAILURE ?def ?delinquent)))))
(assert! `(solved ,?parent)
`(:AND-SUCCESS ,?def
,@ (mapcar #'(lambda (child)
`(SOLVED ,child))
?children))))
(rule ((:IN (OR-SUBGOALS ?parent ?children) :VAR ?def
:TEST ?children))
(dolist (child ?children)
(rlet ((?child (:EVAL child)))
(rassert! (PARENT-OF ?child ?parent :OR)
(:DEF-OF-OR ?def))
(rule ((:IN (SOLVED ?child) :VAR ?winner))
(rassert! (SOLVED ?parent)
(:OR-SUCCESS ?winner ?def)))))
(assert! `(FAILED ,?parent)
`(:OR-FAILURE ,?def
,@ (mapcar #'(lambda (child)
`(FAILED ,child))
?children))))
(rule ((:IN (PARENT-OF ?child ?parent ?type) :VAR ?lineage))
(rassert! (RELEVANT ?child)
(:STILL-WORKING-ON (OPEN ?parent) ?lineage)))
(rule ((:IN (SOLUTION-OF ?problem ?answer) :VAR ?found))
(rassert! (SOLVED ?problem) (:FOUND-ANSWER ?found)))
(rule ((:IN (OR-SUBGOALS (Integrate ?expr) NIL) :VAR ?no-ideas))
(rassert! (FAILED (Integrate ?expr)) (:NO-METHODS ?no-ideas)))
;;;;;;;;;;;;;;;
(rule ((:IN (OR-SUBGOALS ((|$Differentiate| SIMP) ?expr) NIL) :VAR ?no-ideas))
(rassert! (FAILED ((|$Differentiate| SIMP) ?expr)) (:NO-METHODS ?no-ideas)))
;;;;;;;;;;;;;;;
(rule ((:IN (SOLVED ?problem))) ;; Can only happen once
(retract! `(OPEN ,?problem) :EXPAND-AGENDA-ITEM t))
(rule ((:IN (FAILED ?problem)))
(retract! `(OPEN ,?problem) :EXPAND-AGENDA-ITEM t))