;; ADD-QUEUE ;; usage: (add-queue queue '(object priority-weight)) ;; or: (add-queue queue element), where 'element' is a list of pattern (element priority-weight) (defun add-queue (queue element) (cond ( (eq queue ()) ; if the queue is empty ... (list element) ) ; ... return the element as the new queue. ( (> (cadr element) (cadr (car queue))) ; if the element to be added has a higher priority than the car element ... (append (list element) queue) ) ; ... make it the first element of the queue. ( t ; if none of the above ... (append (list (car queue)) (add-queue (cdr queue) element))) ; ... put it into the tail of the queue. ) ) ;; TOP-QUEUE ;; usage: (top-queue queue) (defun top-queue (queue) (car queue) ; The queue is ordered, so give the first element. ) ;; REMOVE-TOP-QUEUE ;; usage: (remove-top-queue queue) (defun remove-top-queue (queue) ; The queue is ordered, so give the tail of the queue. (cdr queue) )