unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* doc ice-9 q
@ 2004-01-08 22:03 Kevin Ryde
  2004-01-09 16:48 ` Stephen Compall
  2004-01-11  0:18 ` Marius Vollmer
  0 siblings, 2 replies; 4+ messages in thread
From: Kevin Ryde @ 2004-01-08 22:03 UTC (permalink / raw)


This is a proposal for some words about the ice-9 q module.

The comments in q.scm have more or less invited applications to make
use of the way a queue is a cons cell, so I think that may as well be
documented.


Queues
======

The functions in this section are provided by

     (use-modules (ice-9 q))

   This module implements queues holding arbitrary scheme objects,
designed for efficient first-in / first-out operations.

   `make-q' creates a queue, and objects are entered and removed with
`enq!' and `deq!'.  `q-push!'  and `q-pop!' can be used too, treating
the front of the queue like a stack.


 - Scheme Procedure: make-q
     Return a new queue.

 - Scheme Procedure: q? obj
     Return `#t' if OBJ is a queue, or `#f' if not.

     Note that queues are not a distinct class of objects but are
     implemented with cons cells.  For that reason certain list
     structures can get `#t' from `q?'.

 - Scheme Procedure: enq! q obj
     Add OBJ to the rear of Q, and return Q.

 - Scheme Procedure: deq! q
 - Scheme Procedure: q-pop! q
     Remove and return the front element from Q.  If Q is empty, a
     `q-empty' exception is thrown.

     `deq!' and `q-pop!' are the same operation, the two names just let
     an application match `enq!' with `deq!', or `q-push!' with
     `q-pop!'.

 - Scheme Procedure: q-push! q obj
     Add OBJ to the front of Q, and return Q.

 - Scheme Procedure: q-length q
     Return the number of elements in Q.

 - Scheme Procedure: q-empty? q
     Return true if Q is empty.

 - Scheme Procedure: q-empty-check q
     Throw a `q-empty' exception if Q is empty.

 - Scheme Procedure: q-front q
     Return the first element of Q (without removing it).  If Q is
     empty, a `q-empty' exception is thrown.

 - Scheme Procedure: q-rear q
     Return the last element of Q (without removing it).  If Q is
     empty, a `q-empty' exception is thrown.

 - Scheme Procedure: q-remove! q obj
     Remove all occurences of OBJ from Q, and return Q.  OBJ is
     compared to queue elements using `eq?'.


   A queue is implemented as a cons cell, the `car' containing a list
of queued elements, and the `cdr' being the last cell in that list
(for ease of enqueuing).

     (LIST . LAST-CELL)

If the queue is empty, LIST is the empty list and LAST-CELL is `#f'.

   An application can directly access the queue list if desired, for
instance to search the elements or to insert at a specific point.

 - Scheme Procedure: sync-q! q
     Recompute the LAST-CELL field in Q.

     All the operations above maintain LAST-CELL as described, so
     normally there's no need for `sync-q!'.  But if an application
     modifies the queue LIST then it must either maintain LAST-CELL
     similarly, or call `sync-q!' to recompute it.



_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2004-01-11  0:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-01-08 22:03 doc ice-9 q Kevin Ryde
2004-01-09 16:48 ` Stephen Compall
2004-01-10 19:43   ` Kevin Ryde
2004-01-11  0:18 ` Marius Vollmer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).