Request for comments on CLOS code

From: Enrico `Trippo' Porreca (eporreca_at_people.it)
Date: 08/28/04


Date: Sat, 28 Aug 2004 00:19:51 +0200

The following is one of my first experiments with the Common Lisp Object
System: the implementation of a FIFO queue. I'd like to hear your
comments (of any kind) about my code.

(defclass queue ()
   ((head :initform nil
          :accessor head)
    (tail :initform nil
          :accessor tail)))

(defmethod emptyp ((queue queue))
   (null (head queue)))

(defmethod enqueue (object (queue queue))
   (let ((new-tail (list object)))
     (if (emptyp queue)
         (setf (head queue) new-tail)
         (rplacd (tail queue) new-tail))
     (setf (tail queue) new-tail)))

(defmethod dequeue ((queue queue))
   (pop (head queue)))

Thanks in advance.

-- 
Enrico `Trippo' Porreca


Relevant Pages

  • Re: [PATCH] scsi_execute_async() should add to the tail of the queue
    ... a SCSI device using that function causes I/Os to be starved from ... of scsi_do_reqand add the request to the tail of the queue. ... some things should really be added to the head of the queue, ... internal commands, not be the default way user issued commands. ...
    (Linux-Kernel)
  • Re: Malcolms new book
    ... may have missed it) and the add function will then just loop forever. ... tricky to calculate the queue length from the head and tail indices, ... int head = 0; ...
    (comp.lang.c)
  • Re: What is the Difference between Shadow and Mirrored disk?
    ... VMS doesn't know the head position; even a controller like an EVA or HSG ... the best you can do is quickly forward a queue of requests to the ... HBVS looks at the local queue lengths for shadowset members from the ... node on which it is running, adds in the Read Cost for each member disk, ...
    (comp.os.vms)
  • [PATCH 27 of 28] IB/ipath - fix races with ib_resize_cq()
    ... The resize CQ function changes the memory used to store the queue. ... Other routines need to honor the lock before accessing the pointer ... to the queue and verify that the head and tail are in range. ... u32 head, tail, n; ...
    (Linux-Kernel)
  • Re: [PATCH] scsi_execute_async() should add to the tail of the queue
    ... >> some things should really be added to the head of the queue, ... > internal commands, not be the default way user issued commands. ... It's worth noting that the hdaps disk protection patches rely on the current behaviour to add 'IDLE IMMEDIATE WITH UNLOAD' commands to the head of the queue.. ...
    (Linux-Kernel)