Next: , Previous: , Up: Top   [Contents][Index]


4 Purely functional queues

This module implements a First–In First–Out functional queue:

(let* ((Q (make-queue))
       (Q (enqueue Q 1))
       (Q (enqueue Q 2))
       (Q (enqueue Q 3)))
  (receive (A Q)
      (dequeue Q)
    (receive (B Q)
        (dequeue Q)
      (receive (C Q)
          (dequeue Q)
        (values A B C)))))
⇒ 1 2 3

by applying repeatedly dequeue to the same <queue> object, we extract the same item from the queue:

(let* ((Q (make-queue))
       (Q (enqueue Q 1))
       (Q (enqueue Q 2))
       (Q (enqueue Q 3)))
  (receive (A Q1)
      (dequeue Q)
    (receive (B Q1)
        (dequeue Q)
      (receive (C Q1)
          (dequeue Q)
        (values A B C)))))
⇒ 1 1 1
Function: make-queue

Return a queue containing no items.

Function: queue? OBJ

Return #t if OBJ is a queue, #f otherwise.

Function: queue-length queue

Return a non–negative integer representing the number of items in queue.

Function: queue-empty? queue

Return #t if there are no items in queue, #f otherwise.

Function: enqueue queue item

Return a new queue with the enqueued item at the end.

Function: dequeue queue

Return 2 values: the item at the front of queue, and a new queue containing the all the other items. Raise a condition with kind pfds-queue-empty-condition condition if queue is empty.

Function: queue-empty-condition? OBJ

Return #t if OBJ is a condition object with kind pfds-queue-empty-condition; otherwise return #f.

Function: queue->list queue

Return a list containing all the items in queue. The order of the item in the list is the same as the order of the elements in the queue.

Function: list->queue list-of-items

Return a queue containing all the items in the given list. The order of the items in the queue is the same as the order in the list.


Next: , Previous: , Up: Top   [Contents][Index]

This document describes version 0.5.0-devel.1 of MMCK PFDS.