Next: , Previous: , Up: iklib lists   [Index]


6.25.2 Queues of items

Queues are object containers that allow constructing a first-in first-out sequence. The following bindings are exported by the library (vicare).

Function: make-queue-procs
Function: make-queue-procs init-values

Build a queue of items and return 3 values:

  1. A predicate thunk returning #t if the queue is empty.
  2. A function which, applied to a single argument, enqueues it as last item.
  3. A thunk extracting and returning the first item from the queue. If the queue is empty an error is raised.

The optional init-values must be null or the list of initial values.

Usage examples:

#!r6rs
(import (vicare))

(let-values (((empty? enqueue! dequeue!)
              (make-queue-procs)))
  (empty?))
⇒ #t

(let-values (((empty? enqueue! dequeue!)
              (make-queue-procs)))
  (enqueue! 1)
  (empty?))
⇒ #f

(let-values (((empty? enqueue! dequeue!)
              (make-queue-procs)))
  (enqueue! 1)
  (empty?)      ⇒ #f
  (dequeue!)    ⇒ 1
  (empty?))
⇒ #t

(let-values (((empty? enqueue! dequeue!)
              (make-queue-procs)))
  (enqueue! 1)
  (enqueue! 2)
  (enqueue! 3)
  (dequeue!)    ⇒ 1
  (dequeue!)    ⇒ 2
  (dequeue!)    ⇒ 3
  (empty?))
⇒ #t