Next: Streams, Previous: File Tree Walk, Up: Guile Modules
The functions in this section are provided by
(use-modules (ice-9 q))
This module implements queues holding arbitrary scheme objects and 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.
Return
#tif obj is a queue, or#fif 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
#tfromq?.
Remove and return the front element from q. If q is empty, a
q-emptyexception is thrown.
deq!andq-pop!are the same operation, the two names just let an application matchenq!withdeq!, orq-push!withq-pop!.
Return the first element of q (without removing it). If q is empty, a
q-emptyexception is thrown.
Return the last element of q (without removing it). If q is empty, a
q-emptyexception is thrown.
Remove all occurences of obj from q, and return q. obj is compared to queue elements using
eq?.
The
q-empty exceptions described above are thrown just as
(throw 'q-empty), there's no message etc like an error throw.
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.