-
Notifications
You must be signed in to change notification settings - Fork 6
/
functor.lisp
48 lines (40 loc) · 1.47 KB
/
functor.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
(in-package #:vivace-graph-v2)
(defstruct (functor
(:constructor %make-functor)
(:predicate functor?))
name fn clauses (lock (make-recursive-lock)))
(defun lookup-functor (name)
(gethash name *user-functors*))
(defun make-functor (&key name clauses)
(or (lookup-functor name)
(let ((functor (%make-functor :name name :clauses clauses)))
(with-recursive-lock-held ((functor-lock functor))
(prog1
(setf (gethash name *user-functors*) functor)
(prolog-compile functor))))))
(defun add-functor-clause (functor clause)
(with-recursive-lock-held ((functor-lock functor))
(cas (cdr (last (functor-clauses functor)))
(cdr (last (functor-clauses functor)))
(list clause))
(prolog-compile functor))
(functor-clauses functor))
(defun delete-functor (functor)
(remhash (functor-name functor) *user-functors*))
(defun reset-functor (functor)
(with-recursive-lock-held ((functor-lock functor))
(cas (functor-clauses functor) (functor-clauses functor) nil)
(prolog-compile functor))
nil)
(defun get-functor-fn (functor-symbol)
(let ((f (lookup-functor functor-symbol)))
(when (functor? f)
(functor-fn f))))
(defun set-functor-fn (functor-symbol fn)
(let ((f (lookup-functor functor-symbol)))
(when *prolog-trace*
(format t "TRACE: set-functor-fn for ~A got ~A~%" functor-symbol f))
(if (functor? f)
(setf (functor-fn f) fn)
(error 'prolog-error
:reason (format nil "unknown functor ~A" functor-symbol)))))