home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / o / ops5.zip / OPS-MAIN.LIS < prev    next >
Lisp/Scheme  |  1992-03-06  |  19KB  |  727 lines

  1. ;
  2. ;************************************************************************
  3. ;
  4. ;    VPS2 -- Interpreter for OPS5
  5. ;
  6. ;
  7. ;
  8. ; This Common Lisp version of OPS5 is in the public domain.  It is based
  9. ; in part on based on a Franz Lisp implementation done by Charles L. Forgy
  10. ; at Carnegie-Mellon University, which was placed in the public domain by
  11. ; the author in accordance with CMU policies.  This version has been
  12. ; modified by George Wood, Dario Giuse, Skef Wholey, Michael Parzen,
  13. ; and Dan Kuokka.
  14. ;
  15. ; This code is made available is, and without warranty of any kind by the
  16. ; authors or by Carnegie-Mellon University.
  17. ;
  18.  
  19. ;;;; This file contains the top-level functions, function to literalize
  20. ;;;; and access attributes, and functions to manage the conflict set.
  21.  
  22.  
  23. (in-package "OPS")
  24.  
  25. (export '(literalize p vector-attribute strategy watch))
  26.  
  27.  
  28. ;;; Global variables also used by other modules.
  29.  
  30. (defvar *halt-flag*)
  31. (defvar *cycle-count*)
  32. (defvar *p-name*)
  33. (defvar *ptrace*)
  34. (defvar *wtrace*)
  35.  
  36.  
  37. ;;; Global variables used in this module only.
  38.  
  39. (defvar *limit-token*)
  40. (defvar *total-wm*)
  41. (defvar *max-token*)
  42. (defvar *total-token*)
  43. (defvar *brkpts*)
  44. (defvar *phase*)
  45. (defvar *break-flag*)
  46. (defvar *remaining-cycles*)
  47. (defvar *conflict-set*)
  48. (defvar *max-cs*)
  49. (defvar *total-cs*)
  50. (defvar *limit-cs*)
  51. (defvar *strategy*)
  52. (defvar *class-list*)
  53. (defvar *buckets*)
  54.  
  55.  
  56.  
  57. (defun main-init ()
  58.   (setq *cycle-count* 0.)
  59.   (setq *p-name* nil)
  60.   (setq *ptrace* t)
  61.   (setq *wtrace* nil)
  62.   (setq *limit-token* 1000000.)
  63.   (setq *limit-cs* 1000000.)
  64.   (setq *total-wm* 0.)
  65.   (setq *total-token* (setq *max-token* 0.))
  66.   (setq *max-cs* (setq *total-cs* 0.))
  67.   (setq *conflict-set* nil)
  68.   (setq *strategy* 'lex)
  69.   (setq *buckets* 127.)        ; regular OPS5 allows 64 named slots
  70.   (setq *class-list* nil)
  71.   (setq *brkpts* nil)
  72.   (setq *remaining-cycles* 1000000))
  73.  
  74.  
  75.  
  76. ;;;; Top level commands.
  77.  
  78.  
  79. (defmacro run (&body z)
  80.   `(ops-run ',z))
  81.  
  82. (defmacro ppwm (&body avlist)
  83.   `(ops-ppwm ',avlist))
  84.  
  85. (defmacro wm (&body a) 
  86.   `(ops-wm ',a))
  87.  
  88. (defmacro pm (&body z)
  89.   `(ops-pm ',z))
  90.  
  91. (defmacro cs (&body z)
  92.   `(ops-cs ',z))
  93.  
  94. (defmacro matches (&body rule-list)
  95.   `(ops-matches ',rule-list))
  96.  
  97. (defmacro strategy (&body z)
  98.   `(ops-strategy ',z))
  99.  
  100. (defmacro watch (&body z)
  101.   `(ops-watch ',z))
  102.  
  103. (defmacro pbreak (&body z)
  104.   `(ops-pbreak ',z))
  105.  
  106. (defmacro excise (&body z)
  107.   `(ops-excise ',z))
  108.  
  109. (defmacro p (&body z) 
  110.   `(ops-p ',z))
  111.  
  112. (defmacro external (&body z) 
  113.   `(ops-external ',z))
  114.  
  115. (defmacro literal (&body z)
  116.   `(ops-literal ',z))
  117.  
  118. (defmacro literalize (&body z)
  119.   `(ops-literalize ',z))
  120.  
  121. (defmacro vector-attribute (&body l)
  122.   `(ops-vector-attribute ',l))
  123.  
  124. (defun top-level-remove (z)
  125.   (cond ((equal z '(*)) (process-changes nil (get-wm nil)))
  126.     (t (process-changes nil (get-wm z))))) 
  127.  
  128.  
  129.  
  130. ;;; Functions for run command
  131.  
  132. (defun ops-run (z)
  133.   (cond ((atom z) (setq *remaining-cycles* 1000000.) (do-continue nil))
  134.     ((and (atom (cdr z)) (numberp (car z)) (> (car z) 0.))
  135.      (setq *remaining-cycles* (car z))
  136.      (do-continue nil))
  137.     (t 'what?))) 
  138.  
  139.  
  140. (defun do-continue (wmi)
  141.   (cond (*critical*
  142.      (terpri)
  143.      (princ '|warning: network may be inconsistent|)))
  144.   (process-changes wmi nil)
  145.   (print-times (main))) 
  146.  
  147.  
  148. (defun process-changes (adds dels)
  149.   (prog (x)
  150.     process-deletes (and (atom dels) (go process-adds))
  151.     (setq x (car dels))
  152.     (setq dels (cdr dels))
  153.     (remove-from-wm x)
  154.     (go process-deletes)
  155.     process-adds (and (atom adds) (return nil))
  156.     (setq x (car adds))
  157.     (setq adds (cdr adds))
  158.     (add-to-wm x nil)
  159.     (go process-adds))) 
  160.  
  161.  
  162. (defun main nil
  163.   (prog (instance r)
  164.     (setq *halt-flag* nil)
  165.     (setq *break-flag* nil)
  166.     (setq instance nil)
  167.     dil  (setq *phase* 'conflict-resolution)
  168.     (cond (*halt-flag*
  169.        (setq r '|end -- explicit halt|)
  170.        (go finis))
  171.       ((zerop *remaining-cycles*)
  172.        (setq r '***break***)
  173.        (setq *break-flag* t)
  174.        (go finis))
  175.       (*break-flag* (setq r '***break***) (go finis)))
  176.     (setq *remaining-cycles* (1- *remaining-cycles*))
  177.     (setq instance (conflict-resolution))
  178.     (cond ((not instance)
  179.        (setq r '|end -- no production true|)
  180.        (go finis)))
  181.     (setq *phase* (car instance))
  182.     (accum-stats)
  183.     (eval-rhs (car instance) (cdr instance))
  184.     (check-limits)
  185.     (and (broken (car instance)) (setq *break-flag* t))
  186.     (go dil)
  187.     finis (setq *p-name* nil)
  188.     (return r))) 
  189.  
  190.  
  191. (defun broken (rule) (member rule *brkpts*))
  192.  
  193.  
  194. (defun accum-stats nil
  195.   (setq *cycle-count* (1+ *cycle-count*))
  196.   (setq *total-token* (+ *total-token* *current-token*))
  197.   ;"plus" changed to "+" by gdw
  198.   (cond ((> *current-token* *max-token*)
  199.      (setq *max-token* *current-token*)))
  200.   (setq *total-wm* (+ *total-wm* *current-wm*))    ;"plus" changed to "+" by gdw
  201.   (cond ((> *current-wm* *max-wm*) (setq *max-wm* *current-wm*)))) 
  202.  
  203.  
  204. (defun check-limits nil
  205.   (cond ((> (length *conflict-set*) *limit-cs*)
  206.      (format t "~%~%conflict set size exceeded the limit of ~D after ~D~%"
  207.          *limit-cs* *p-name*)
  208.      (setq *halt-flag* t)))
  209.   (cond ((> *current-token* *limit-token*)
  210.      (format t "~%~%token memory size exceeded the limit of ~D after ~D~%"
  211.          *limit-token* *p-name*)
  212.      (setq *halt-flag* t))))
  213.  
  214.  
  215. (defun print-times (mess)
  216.   (prog (cc)
  217.     (cond (*break-flag* (terpri) (return mess)))
  218.     (setq cc (+ (float *cycle-count*) 1.0e-20))
  219.     (terpri)
  220.     (princ mess)
  221.     (terpri)
  222.     (format t "~3D productions (~D // ~D nodes)~%"
  223.         *pcount* *real-cnt* *virtual-cnt*)
  224.     (format t "~3D firings (~D rhs actions)~%"
  225.         *cycle-count* *action-count*)
  226.     (format t "~3D mean working memory size (~D maximum)~%"
  227.         (round (float *total-wm*) cc) *max-wm*)
  228.     (format t "~3D mean conflict set size (~D maximum)~%"
  229.         (round (float *total-cs*) cc) *max-cs*)
  230.     (format t "~3D mean token memory size (~D maximum)~%"
  231.         (round (float *total-token*) cc)
  232.         *max-token*)))
  233.  
  234.  
  235. ;;; Functions for strategy command
  236.  
  237. (defun ops-strategy (z)
  238.   (cond ((atom z) *strategy*)
  239.     ((equal z '(lex)) (setq *strategy* 'lex))
  240.     ((equal z '(mea)) (setq *strategy* 'mea))
  241.     (t 'what?))) 
  242.  
  243.  
  244. ;;; Functions for watch command
  245.  
  246. (defun ops-watch (z)
  247.   (cond ((equal z '(0.))
  248.      (setq *wtrace* nil)
  249.      (setq *ptrace* nil)
  250.      0.)
  251.     ((equal z '(1.)) (setq *wtrace* nil) (setq *ptrace* t) 1.)
  252.     ((equal z '(2.)) (setq *wtrace* t) (setq *ptrace* t) 2.)
  253.     ((equal z '(3.))
  254.      (setq *wtrace* t)
  255.      (setq *ptrace* t)
  256.      '(2. -- conflict set trace not supported))
  257.     ((and (atom z) (null *ptrace*)) 0.)
  258.     ((and (atom z) (null *wtrace*)) 1.)
  259.     ((atom z) 2.)
  260.     (t 'what?))) 
  261.  
  262.  
  263. ;;; Functions for excise command
  264.  
  265. (defun ops-excise (z) (mapc (function excise-p) z))
  266.  
  267. (defun excise-p (name)
  268.   (cond ((and (symbolp name) (get name 'topnode))
  269.      (format t "~S is excised~%" name)
  270.      (setq *pcount* (1- *pcount*))
  271.      (remove-from-conflict-set name)
  272.      (kill-node (get name 'topnode))
  273.      (remprop name 'production)
  274.      (remprop name 'backpointers)
  275.      (remprop name 'topnode)))) 
  276.  
  277. (defun kill-node (node)
  278.   (prog nil
  279.     top  (and (atom node) (return nil))
  280.     (rplaca node '&old)
  281.     (setq node (cdr node))
  282.     (go top))) 
  283.  
  284.  
  285. ;;; Functions for external command
  286.  
  287. (defun ops-external (z) (catch '!error! (external2 z))) ;jgk inverted args
  288. ;& quoted tag
  289. (defun external2 (z) (mapc (function external3) z))
  290.  
  291. (defun external3 (x) 
  292.   (cond ((symbolp x) (putprop x t 'external-routine))
  293.     (t (%error '|not a legal function name| x))))
  294.  
  295. ;;; Functions for pbreak command
  296.  
  297. (defun ops-pbreak (z)
  298.   (cond ((atom z) (terpri) *brkpts*)
  299.     (t (mapc (function pbreak2) z) nil)))
  300.  
  301. (defun pbreak2 (rule)
  302.   (cond ((not (symbolp rule)) (%warn '|illegal name| rule))
  303.     ((not (get rule 'topnode)) (%warn '|not a production| rule))
  304.     ((member rule *brkpts*) (setq *brkpts* (rematm rule *brkpts*)))
  305.     (t (setq *brkpts* (cons rule *brkpts*)))))
  306.  
  307. (defun rematm (atm list)
  308.   (cond ((atom list) list)
  309.     ((eq atm (car list)) (rematm atm (cdr list)))
  310.     (t (cons (car list) (rematm atm (cdr list))))))
  311.  
  312.  
  313. ;;; Functions for matches command
  314.  
  315. (defun ops-matches (rule-list)
  316.   (mapc (function matches2) rule-list)
  317.   (terpri)) 
  318.  
  319.  
  320. (defun matches2 (p)
  321.   (cond ((atom p)
  322.      (terpri)
  323.      (terpri)
  324.      (princ p)
  325.      (matches3 (get p 'backpointers) 2. (ncons 1.))))) 
  326.  
  327.  
  328. (defun matches3 (nodes ce part)
  329.   (cond ((not (null nodes))
  330.      (terpri)
  331.      (princ '| ** matches for |)
  332.      (princ part)
  333.      (princ '| ** |)
  334.      (mapc (function write-elms) (find-left-mem (car nodes)))
  335.      (terpri)
  336.      (princ '| ** matches for |)
  337.      (princ (ncons ce))
  338.      (princ '| ** |)
  339.      (mapc (function write-elms) (find-right-mem (car nodes)))
  340.      (matches3 (cdr nodes) (1+ ce) (cons ce part))))) 
  341.  
  342.  
  343. (defun write-elms (wme-or-count)
  344.   (cond ((consp  wme-or-count)    ;dtpr\consp gdw
  345.      (terpri)
  346.      (mapc (function write-elms2) wme-or-count)))) 
  347.  
  348.  
  349. (defun write-elms2 (x)
  350.   (princ '|  |)
  351.   (princ (creation-time x)))
  352.  
  353.  
  354. (defun find-left-mem (node)
  355.   (cond ((eq (car node) '&and) (memory-part (caddr node)))
  356.     (t (car (caddr node))))) 
  357.  
  358.  
  359. (defun find-right-mem (node) (memory-part (cadddr node))) 
  360.  
  361.  
  362. ;;; Function for cs command.
  363.  
  364. (defun ops-cs (z)
  365.   (cond ((atom z) (conflict-set))
  366.     (t 'what?))) 
  367.  
  368.  
  369.  
  370. ;;;; Functions for literalize and related operations.
  371.  
  372. (defun ops-literal (z)
  373.   (prog (atm val old)
  374.     top  (and (atom z) (return 'bound))
  375.     (or (eq (cadr z) '=) (return (%warn '|wrong format| z)))
  376.     (setq atm (car z))
  377.     (setq val (caddr z))
  378.     (setq z (cdddr z))
  379.     (cond ((not (numberp val))
  380.        (%warn '|can bind only to numbers| val))
  381.       ((or (not (symbolp atm)) (variablep atm))
  382.        (%warn '|can bind only constant atoms| atm))
  383.       ((and (setq old (literal-binding-of atm)) (not (equal old val)))
  384.        (%warn '|attempt to rebind attribute| atm))
  385.       (t (putprop atm val 'ops-bind)))
  386.     (go top))) 
  387.  
  388.  
  389. (defun ops-literalize (l)
  390.   (prog (class-name atts)
  391.     (setq class-name (car l))
  392.     (cond ((have-compiled-production)
  393.        (%warn '|literalize called after p| class-name)
  394.        (return nil))
  395.       ((get class-name 'att-list)
  396.        (%warn '|attempt to redefine class| class-name)
  397.        (return nil)))
  398.     (setq *class-list* (cons class-name *class-list*))
  399.     (setq atts (remove-duplicates (cdr l)))        ; ??? should this
  400.     ; warn of dup atts?
  401.     (test-attribute-names atts)
  402.     (mark-conflicts atts atts)
  403.     (putprop class-name atts 'att-list))) 
  404.  
  405. (defun ops-vector-attribute (l)
  406.   (cond ((have-compiled-production)
  407.      (%warn '|vector-attribute called after p| l))
  408.     (t 
  409.      (test-attribute-names l)
  410.      (mapc (function vector-attribute2) l)))) 
  411.  
  412. (defun vector-attribute2 (att) (putprop att t 'vector-attribute))
  413.  
  414. (defun is-vector-attribute (att) (get att 'vector-attribute))
  415.  
  416. (defun test-attribute-names (l)
  417.   (mapc (function test-attribute-names2) l)) 
  418.  
  419. (defun test-attribute-names2 (atm)
  420.   (cond ((or (not (symbolp atm)) (variablep atm))
  421.      (%warn '|can bind only constant atoms| atm)))) 
  422.  
  423. (defun finish-literalize nil
  424.   (cond ((not (null *class-list*))
  425.      (mapc (function note-user-assigns) *class-list*)
  426.      (mapc (function assign-scalars) *class-list*)
  427.      (mapc (function assign-vectors) *class-list*)
  428.      (mapc (function put-ppdat) *class-list*)
  429.      (mapc (function erase-literal-info) *class-list*)
  430.      (setq *class-list* nil)
  431.      (setq *buckets* nil)))) 
  432.  
  433. (defun have-compiled-production nil (not (zerop *pcount*))) 
  434.        
  435. (defun put-ppdat (class)
  436.   (prog (al att ppdat)
  437.     (setq ppdat nil)
  438.     (setq al (get class 'att-list))
  439.     top  (cond ((not (atom al))
  440.         (setq att (car al))
  441.         (setq al (cdr al))
  442.         (setq ppdat
  443.               (cons (cons (literal-binding-of att) att)
  444.                 ppdat))
  445.         (go top)))
  446.     (putprop class ppdat 'ppdat))) 
  447.  
  448. ; note-user-assigns and note-user-vector-assigns are needed only when
  449. ; literal and literalize are both used in a program.  They make sure that
  450. ; the assignments that are made explicitly with literal do not cause problems
  451. ; for the literalized classes.
  452.  
  453. (defun note-user-assigns (class)
  454.   (mapc (function note-user-assigns2) (get class 'att-list)))
  455.  
  456. (defun note-user-assigns2 (att)
  457.   (prog (num conf buck clash)
  458.     (setq num (literal-binding-of att))
  459.     (and (null num) (return nil))
  460.     (setq conf (get att 'conflicts))
  461.     (setq buck (store-binding att num))
  462.     (setq clash (find-common-atom buck conf))
  463.     (and clash
  464.      (%warn '|attributes in a class assigned the same number|
  465.         (cons att clash)))
  466.     (return nil)))
  467.  
  468. (defun note-user-vector-assigns (att given needed)
  469.   (and (> needed given)
  470.        (%warn '|vector attribute assigned too small a value in literal| att)))
  471.  
  472. (defun assign-scalars (class)
  473.   (mapc (function assign-scalars2) (get class 'att-list))) 
  474.  
  475. (defun assign-scalars2 (att)
  476.   (prog (tlist num bucket conf)
  477.     (and (literal-binding-of att) (return nil))
  478.     (and (is-vector-attribute att) (return nil))
  479.     (setq tlist (buckets))
  480.     (setq conf (get att 'conflicts))
  481.     top  (cond ((atom tlist)
  482.         (%warn '|could not generate a binding| att)
  483.         (store-binding att -1.)
  484.         (return nil)))
  485.     (setq num (caar tlist))
  486.     (setq bucket (cdar tlist))
  487.     (setq tlist (cdr tlist))
  488.     (cond ((disjoint bucket conf) (store-binding att num))
  489.       (t (go top))))) 
  490.  
  491. (defun assign-vectors (class)
  492.   (mapc (function assign-vectors2) (get class 'att-list))) 
  493.  
  494. (defun assign-vectors2 (att)
  495.   (prog (big conf new old need)
  496.     (and (not (is-vector-attribute att)) (return nil))
  497.     (setq big 1.)
  498.     (setq conf (get att 'conflicts))
  499.     top  (cond ((not (atom conf))
  500.         (setq new (car conf))
  501.         (setq conf (cdr conf))
  502.         (cond ((is-vector-attribute new)
  503.                (%warn '|class has two vector attributes|
  504.                   (list att new)))
  505.               (t (setq big (max (literal-binding-of new) big))))
  506.         (go top)))
  507.     (setq need (1+ big))            ;"plus" changed to "+" by gdw
  508.     (setq old (literal-binding-of att))
  509.     (cond (old (note-user-vector-assigns att old need))
  510.       (t (store-binding att need)))
  511.     (return nil)))
  512.  
  513. (defun disjoint (la lb) (not (find-common-atom la lb))) 
  514.  
  515. (defun find-common-atom (la lb)
  516.   (prog nil
  517.     top  (cond ((null la) (return nil))
  518.            ((member (car la) lb) (return (car la)))
  519.            (t (setq la (cdr la)) (go top))))) 
  520.  
  521. (defun mark-conflicts (rem all)
  522.   (cond ((not (null rem))
  523.      (mark-conflicts2 (car rem) all)
  524.      (mark-conflicts (cdr rem) all)))) 
  525.  
  526. (defun mark-conflicts2 (atm lst)
  527.   (prog (l)
  528.     (setq l lst)
  529.     top  (and (atom l) (return nil))
  530.     (conflict atm (car l))
  531.     (setq l (cdr l))
  532.     (go top))) 
  533.  
  534. (defun conflict (a b)
  535.   (prog (old)
  536.     (setq old (get a 'conflicts))
  537.     (and (not (eq a b))
  538.      (not (member b old))
  539.      (putprop a (cons b old) 'conflicts)))) 
  540.  
  541. ;@@@ use intrinsic 
  542. ;(defun remove-duplicates  (lst)
  543.    ;  (cond ((atom lst) nil)
  544.         ;        ((member (car lst) (cdr lst)) (remove-duplicates (cdr lst)))
  545.         ;        (t (cons (car lst) (remove-duplicates (cdr lst)))))) 
  546.  
  547. (defun literal-binding-of (name) (get name 'ops-bind)) 
  548.  
  549. (defun store-binding (name lit)
  550.   (putprop name lit 'ops-bind)
  551.   (add-bucket name lit)) 
  552.  
  553. (defun add-bucket (name num)
  554.   (prog (buc)
  555.     (setq buc (assoc num (buckets)))
  556.     (and (not (member name buc))
  557.      (rplacd buc (cons name (cdr buc))))
  558.     (return buc))) 
  559.  
  560. (defun buckets nil
  561.   (and (atom *buckets*) (setq *buckets* (make-nums *buckets*)))
  562.   *buckets*) 
  563.  
  564. (defun make-nums (k)
  565.   (prog (nums)
  566.     (setq nums nil)
  567.     l    (and (< k 2.) (return nums))
  568.     (setq nums (cons (ncons k) nums))
  569.     (setq k (1- k))
  570.     (go l))) 
  571.  
  572. (defun erase-literal-info (class)
  573.   (mapc (function erase-literal-info2) (get class 'att-list))
  574.   (remprop class 'att-list)) 
  575.  
  576. (defun erase-literal-info2 (att) (remprop att 'conflicts)) 
  577.  
  578.  
  579.  
  580.  
  581. ;;;; Functions for conflict set management and resolution.
  582.  
  583.  
  584. ;;; Each conflict set element is a list of the following form:
  585. ;;; ((p-name . data-part) (sorted wm-recency) special-case-number)
  586.  
  587. (defun conflict-resolution nil
  588.   (prog (best len)
  589.     (setq len (length *conflict-set*))
  590.     (cond ((> len *max-cs*) (setq *max-cs* len)))
  591.     (setq *total-cs* (+ *total-cs* len))    ;"plus" changed to "+" by gdw
  592.     (cond (*conflict-set*
  593.        (setq best (best-of *conflict-set*))
  594.        (setq *conflict-set* (delq best *conflict-set*))
  595.        (return (pname-instantiation best)))
  596.       (t (return nil))))) 
  597.  
  598. (defun removecs (name data)
  599.   (prog (cr-data inst cs)
  600.     (setq cr-data (cons name data))
  601.     (setq cs *conflict-set*)
  602.     loop    (cond ((null cs) 
  603.                (record-refract name data)
  604.                (return nil)))
  605.     (setq inst (car cs))
  606.     (setq cs (cdr cs))
  607.     (and (not (top-levels-eq (car inst) cr-data)) (go loop))
  608.     (setq *conflict-set* (delq inst *conflict-set*))))
  609.  
  610. (defun insertcs (name data rating)
  611.   (prog (instan)
  612.     (and (refracted name data) (return nil))
  613.     (setq instan (list (cons name data) (order-tags data) rating))
  614.     (and (atom *conflict-set*) (setq *conflict-set* nil))
  615.     (return (setq *conflict-set* (cons instan *conflict-set*))))) 
  616.  
  617.  
  618. (defun remove-from-conflict-set (name)
  619.   (prog (cs entry)
  620.     l1   (setq cs *conflict-set*)
  621.     l2   (cond ((atom cs) (return nil)))
  622.     (setq entry (car cs))
  623.     (setq cs (cdr cs))
  624.     (cond ((eq name (caar entry))
  625.        (setq *conflict-set* (delq entry *conflict-set*))
  626.        (go l1))
  627.       (t (go l2))))) 
  628.  
  629. (defun order-tags (dat)
  630.   (prog (tags)
  631.     (setq tags nil)
  632.     l1p  (and (atom dat) (go l2p))
  633.     (setq tags (cons (creation-time (car dat)) tags))
  634.     (setq dat (cdr dat))
  635.     (go l1p)
  636.     l2p  (cond ((eq *strategy* 'mea)
  637.         (return (cons (car tags) (dsort (cdr tags)))))
  638.            (t (return (dsort tags)))))) 
  639.  
  640. ; destructively sort x into descending order
  641.  
  642. (defun dsort (x)
  643.   (prog (sorted cur next cval nval)
  644.     (and (atom (cdr x)) (return x))
  645.     loop (setq sorted t)
  646.     (setq cur x)
  647.     (setq next (cdr x))
  648.     chek (setq cval (car cur))
  649.     (setq nval (car next))
  650.     (cond ((> nval cval)
  651.        (setq sorted nil)
  652.        (rplaca cur nval)
  653.        (rplaca next cval)))
  654.     (setq cur next)
  655.     (setq next (cdr cur))
  656.     (cond ((not (null next)) (go chek))
  657.       (sorted (return x))
  658.       (t (go loop))))) 
  659.  
  660. (defun best-of (set) (best-of* (car set) (cdr set))) 
  661.  
  662. (defun best-of* (best rem)
  663.   (cond ((not rem) best)
  664.     ((conflict-set-compare best (car rem))
  665.      (best-of* best (cdr rem)))
  666.     (t (best-of* (car rem) (cdr rem))))) 
  667.  
  668. (defun pname-instantiation (conflict-elem) (car conflict-elem)) 
  669.  
  670. (defun order-part (conflict-elem) (cdr conflict-elem)) 
  671.  
  672. (defun instantiation (conflict-elem)
  673.   (cdr (pname-instantiation conflict-elem))) 
  674.  
  675.  
  676. (defun conflict-set-compare (x y)
  677.   (prog (x-order y-order xl yl xv yv)
  678.     (setq x-order (order-part x))
  679.     (setq y-order (order-part y))
  680.     (setq xl (car x-order))
  681.     (setq yl (car y-order))
  682.     data (cond ((and (null xl) (null yl)) (go ps))
  683.            ((null yl) (return t))
  684.            ((null xl) (return nil)))
  685.     (setq xv (car xl))
  686.     (setq yv (car yl))
  687.     (cond ((> xv yv) (return t))
  688.       ((> yv xv) (return nil)))
  689.     (setq xl (cdr xl))
  690.     (setq yl (cdr yl))
  691.     (go data)
  692.     ps   (setq xl (cdr x-order))
  693.     (setq yl (cdr y-order))
  694.     psl  (cond ((null xl) (return t)))
  695.     (setq xv (car xl))
  696.     (setq yv (car yl))
  697.     (cond ((> xv yv) (return t))
  698.       ((> yv xv) (return nil)))
  699.     (setq xl (cdr xl))
  700.     (setq yl (cdr yl))
  701.     (go psl))) 
  702.  
  703.  
  704. (defun conflict-set nil
  705.   (prog (cnts cs p z best)
  706.     (setq cnts nil)
  707.     (setq cs *conflict-set*)
  708.     l1p  (and (atom cs) (go l2p))
  709.     (setq p (caaar cs))
  710.     (setq cs (cdr cs))
  711.     (setq z (assq p cnts))
  712.     (cond ((null z) (setq cnts (cons (cons p 1.) cnts)))
  713.       (t (rplacd z (1+ (cdr z)))))
  714.     (go l1p)
  715.     l2p  (cond ((atom cnts)
  716.         (setq best (best-of *conflict-set*))
  717.         (terpri)
  718.         (return (list (caar best) 'dominates))))
  719.     (terpri)
  720.     (princ (caar cnts))
  721.     (cond ((> (cdar cnts) 1.)
  722.        (princ '|    (|)
  723.           (princ (cdar cnts))
  724.           (princ '| occurrences)|)))
  725.     (setq cnts (cdr cnts))
  726.     (go l2p))) 
  727.