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


5 Double queues

This module implements a functional deque:

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

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

by applying repeatedly the dequeue functions to the same <deque> object, we extract the same item:

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

Return a deque containing to items.

Function: deque? OBJ

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

Function: deque-length deque

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

Function: deque-empty? deque

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

Function: enqueue-front deque item

Return a new deque with the item inserted at the front.

Function: enqueue-rear deque item

Return a new deque with the item inserted at the rear.

Function: dequeue-front deque

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

Function: dequeue-rear deque

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

Function: deque-empty-condition? OBJ

Return #t if OBJ is a condition with kind pfds-deque-empty-condition, #f otherwise.

Function: deque->list deque

Return a list containing all the elements of deque. The order of the elements in the list is the same as the order they would be dequeued from the front of the deque.

Function: list->deque list-of-items

Return a deque containing all of the elements in the list argument. The order of the elements in the deque is the same as the order of the elements in the list.


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

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